tags:

views:

384

answers:

4
echo 'Tok: '.$tok.' Strpos: '.strpos($tok, "\"").' length: '.strlen($tok).'<br>';

And this:

echo 'Tok: '.$tok.' Strpos: '.strpos($tok, '"').' length: '.strlen($tok).'<br>';

Result in the following output:

Tok: "fresh Strpos: length: 11

Strpos is failing completely to find the double quote, it returns false (I checked with strpos() === false). Can someone tell me what's going on here? I can find no documentation suggesting that strpos can't handle double quotes, why isn't it finding it? I am at my wits end.

+4  A: 

Are you 1000% sure that the double quote in $tok is actually a literal " and not a HTML entity? Can you check your HTML code?

Pekka
This. Check the source of the webpage when you echo $tok.
Daniel
Was just coming back to post that I'd discovered that. It's an HTML entity alright: " *head desk* Input sanitization for the fail.
Daniel Bingham
Input “sanitisation” totally for the fail at all times! HTML-encoding must not happen until the moment you put the text into HTML output; doing it at the input stage is doomed to failure, messed up database contents and security holes where other content comes in.
bobince
+1  A: 

Using php at the command line, your code works for me.

I noticed you didn't specify the content of $tok. I also noticed it lookes like you're outputting to a browser. Are you sure that the html

&quot

isn't being used instead of the actual quote character?

Doug T.
A: 

strpos($tok, '"') is equaling === 0 in your case since the very first element in $tok is a double-quote ("). Then when you print out 0 you get nothing because it is a boolean FALSE.

This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function - http://us3.php.net/strpos

Xeoncross
Nah, only when it's FALSE the output will be empty; otherwise it should be a numeric `0` shouldn't it`?
Pekka
A: 

Its working for me in 5.3.0...

Rifat