Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PHP, strpos() fails to find double quote ('"') in string

Tags:

php

strpos

Both this:

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.

like image 449
Daniel Bingham Avatar asked Oct 21 '25 03:10

Daniel Bingham


2 Answers

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?

like image 124
Pekka Avatar answered Oct 22 '25 17:10

Pekka


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?

like image 37
Doug T. Avatar answered Oct 22 '25 18:10

Doug T.