php strpos special characters
Posted
by Radu
on Stack Overflow
See other posts from Stack Overflow
or by Radu
Published on 2010-05-12T12:53:42Z
Indexed on
2010/05/12
13:04 UTC
Read the original article
Hit count: 247
I'm using PHP Version 5.1.6
I have a string (session file) and need to extract a value from it, so i'm searching for a needle in the string but it returns false, I reduced the code to this:
$string = ';SERVER_NAME|s:17:"stackoverflow.com";REMOTE_ADDR|s:13:"69.59.196.211";';
$start = strpos($string, ';SERVER_NAME|s:"');
echo $start; // prints nothing because $start = false
$start = strpos($string, 'SERVER_NAME|s:');
echo $start; // prints 1;
As you noticed if I have the character ';' or the character '"' in the needle, the search returns false, I tryed to use chr() for all characters in the needle but had the same result, If I remove the ';' and the '"' from the string if finds the needle in the string.
How can I search special characters in a string using PHP ?
© Stack Overflow or respective owner