How to escape a slash while reading an excel - php

Im reading an excel line by line and doing some php operations in the backend ,but when i reached a cell containing "\" it throwed an error
it has to match the cell value and backend value
cell value "test-123\/123a"
backend value "test123/123a"
i tried reading the cell value as this str_replace("\/","/",$cellvalue);
But error still persists

You can try php function stripslashes http://php.net/manual/en/function.stripslashes.php

Related

php htmlentities on a variable

this prints out nothing
print htmlentities($variable);
this prints out my text string that is a field from mysql that is a mediumtext. The field is 65MB
print $variable;
The question is: does htmlentities have a problem with the size of the variable or is there an obvious way (that I am missing) to debug this ?
Silly enough this is the first time I had this come up and failed to read the manual :(
The fix was to:
print htmlentities($variable,ENT_SUBSTITUTE);
my first attempt to use ENT_IGNORE allowed the string to print but may have security implications https://www.php.net/htmlentities
I apologize that I assumed this was a variable size issue, as all the other few hundred results would print, this made me think this was the only result that did not print just after enlarging the field in mysql, then all of a sudden this started happening. Instead the last bit of data I added to the field had a copyright non ascii character :( sigh

Possible to start printing on 3rd label on 2nd row with FPDF or TCPDF?

Is it possible to start printing on a particular label (set by a $_POST) value? If I have 10 labels to a page, and I want them to start on the 3rd label (2nd label on the 2nd row), is there a way to tell either FPDF or TCPDF to do that?
Update:
This is where the class for fPDF labels comes from:
fPDF Label Class
The line of code that controls this in fPDF is:
function __construct($format, $unit='mm', $posX=1, $posY=1)
When I change the $posx=__ and the $posY=__, the labels DO start printing in different positions!
However, when I set:
function __construct($format, $unit='mm', $posX=$setthex, $posY=$setthey)
I get an error: PHP Fatal error: Constant expression contains invalid operations
I've read about this on SO, but I'm at a loss regarding 'Static' issues...
I figured it out, kind of .. Not with these variables, but by inserting X amount of blank labels before I started printing the correct ones.

PHPMyAdmin inline edit corrupting serialized data in text field

I have a serialized object stored in a mysql database in a column of type text saved via php.
If I double click the field in PHPMyAdmin to edit the value of the field inline, and then save the edit by clicking away from the edit box, the serialized data in the field is rendered corrupt somehow.
I get the following PHP error after doing this:
Notice: unserialize(): Error at offset 913 of 1951 bytes in /path/to/file.php on line 46
I am not even changing any of the data, as I am only clicking in to copy the data to the clipboard so it's not as though I'm introducing anything weird, or making an error with the syntax etc. I thought maybe some whitespace is getting added or some wierd character(s).
Is there a solution to this?
According to this question, in order to avoid errors you can try to base64 the output or serialize() before inserting it into the database:
$toDatabse = base64_encode(serialize($data)); // Save to database
$fromDatabase = unserialize(base64_decode($data)); //Getting Save Format
There is a bug in phpmyadmin that saves the '\n' of a serialized php string as line breaks. PHP serialized strings must not contain line breaks! If you want to safely modify it directly from phpmyadmin, make sure to replace the line breaks with '\n' string, this can easily be done from any text editor.

Where is the data coming from?

It seems I met this problem before, in a different disguise. When a file was being "included" in my main php file before starting a session in that same main php file, I'd get the "headers already sent" error because my included php had a blank line at the start, which was being somehow sent before anything should be sent. Delete blank line, "problem solved"...
Now I have this ajax thingy where I scan a certain string returned by a php. The string I hardcoded in this php to be returned to the ajax callback was the string "alert", which was never seen. I scan what is being received by the callback, and guess what? It has a character 10 starting my 5 character "alert" string.
Sounds familiar? yes, I had an include before the "echo("alert");", and that include'd file DID start with a blank line (too! why I keep doing this???). Delete line, and now I don't get the character 10 (ascii "new line" eh?) starting my "alert" string anymore.
The question: why is the php echo'ing a "new line" character that was never formally "echoed" along with my carefully crafted string? Is this a bug of mine or php? Thanks in advance.
Everything not inside your <?php ... ?> tags is treated as text and sent to the client. So make sure not to have empty lines in your source files...
Edit: The purpose of this is to have a simple way to have a HTML file mixed with portions of PHP code without the need to echo all the HTML stuff explicitly...

php, string value, length and integer value of a variable don't matche

I am getting a variable from a socket. After reading the respond I am trying to convert the value to a number. if I print the respond it looks correct however when I convert it to number using floor() it doesn't give me the right answer. I also tried to print the length of the variable and it is still not working as it suppose to: This one is for value :185
echo("**************** ".floor($res[0]));
echo "################### $res[0]";
echo "------------- ".strlen($res[0]);
output:
**************** 1################### 185------------- 12
I have also tried stripslashes, trim and also ereg_replace('[:cntrl:]', '',$res[0])
Please try the following: intval($res[0])
You can try also with:
$res = (int)$reg[0];
Hope this helps.
Bye
Ok I found the problem. I saved the value in a file and opened the file using notepad++. I saw the following character in between my string:
SOH,NULL, and bunch of other non character values
What I am assuming is PHP automatically ignore the ASCII values are not show able on the screen (less than 21Hex).

Categories