Hi,
I'm having trouble finding single quotes in a string using strpos, strpos is returning the incorrect position.
The code parses SQL statements and extracts any parameters (e.g. where field = 'Parameter'). The SQL parameters are encapsulated in apostrophies (or single quotes). The code looks like this:
$SingleQuote = "'"; //have tried escaping this but the results are teh same
$StartPos = strpos($String,$SingleQuote,$ctr);
if($StartPos === false)
{
//no further processing required
}
else
{
$EndPos = strpos($String,$SingleQuote,$StartPos + 1);
}
kl($String . " -> " . $SingleQuote . ' -> ' . $StartPos . ' -> ' . $EndPos); //this is my own function that basically exits the application.
....returns this result
select cat_table, cat_key, cat_field_status, cat_field_location from bp_object_type where object_type = 'AP' -> ' -> 135 -> 138
The first apostrophe is at position 105, not 135 and the second at 108 not 138.
I've tested the above code by using other characters and it works perfectly. I've also tried using addslashes and the result is the same.
I really want to use the strpos function as it is (I'm lead to believe) the fastest of all the string searching functions and there will be a large number of calls to this function at any given time.
Any help is greatly appreciated.
Thanks in advance
We are using v4.3.9 here at work