|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2002-05-16 17:10 UTC] svemir at baltok dot com
 This script:
<?php
 $needle = "foo";
 echo "1: ";
 echo strstr("Moo _bar_", "_$needle_");
 echo "<br>2: ";
 echo strstr("Moo _bar_", "_{$needle}_");
 echo "<br>3: ";
 echo strstr("Moo _foo_", "_{$needle}_");
 echo "<br>4: ";
 echo strstr("Moo !bar!", "!$needle!");
?>
Gives this output:
1: _bar_
2: 
3: _foo_
4:
Obviously, the line 1 is the problem. If both "haystack" and "needle" have the strings surrounded by underscores - the strings are matched even if they are actually different. This happens only if the "needle" has a variable between the underscores, and the variable is not surrounded by { and }.
Prehaps I am missing something and the combination of "_$" is supposed to mean something, but i did not see it in the documentation.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 04:00:01 2025 UTC | 
You're missing something indeed, _$needle_ is equivalent with "." . ${"needle_"} as underscores can be part of a variablename. As $needle_ is empty, the needle evaluates to "_", which is in "Moo _bar_" Not a bug > bogus. Derick