Unable to get strpos() to work correctly in class method
| From: | JEofVA | Date: | Thu, 26 Feb 2015 15:42:26 +0000 |
| Subject: | Unable to get strpos() to work correctly in class method | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-324530@lists.php.net to get a copy of this message | ||
I have written a class with a method that uses the strpos() function, but I can't get it to work. However, when I use the method as a function in a simple test program that uses the identical code to simulate the class method (and feed it the same strings) it works exactly like I expect.
Below is an abbreviated version of the non-working method version. However, both versions are identical to this point, only this doesn't work while the test program version does. The problem is that the
while-loop never executes because $start always comes up false (but
only in the class version).
protected function extract_quotes($string) // Assumes if $string has quotes they are an even number of them // Uses class property $keywrd_frags to store parsed fragments {What am I overlooking in the class version that keeps the code from working there? Tried: I've tried 37 dozen different variations on this theme, including dropping the $delim variable and using '"' in the strpos() function. I've also used different delimiters, and even changed the delimiter character once the string got into the extract_quotes() function. No difference. Running:$delm = chr(34); // quote char in this case // start parsing from first character of incoming query string $start = strpos($string, $delm, 0); //<=== POINT OF FAILURE while($start !== FALSE) { // the while loop extracts all the delimited blocks of text // one at a time until there are none left. At that point // $start will be false and $string will have only// un-delimited text (or an empty string)//This section never runs because $start is always FALSE} // No more delimited text, so return the remaining $string return $string;}
Apache Version : 2.2.17 PHP Version : 5.3.3Thanks for any ideas, Jonathan