Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • \$\begingroup\$ Couldn't something like this work: !strlen(str_replace($a,'',$b)); It should return 1 if two strings are equal? \$\endgroup\$ Commented Mar 17, 2014 at 14:40
  • \$\begingroup\$ @D.Kasipovic Interesting, but I think it fails for $a == 'foo' and $b = 'foofoo' :) \$\endgroup\$ Commented Mar 17, 2014 at 16:10
  • \$\begingroup\$ True, how about this then, it limits replace to one !strlen(preg_replace("/{$a}/", '', $b, 1)); and is 45 characters? \$\endgroup\$ Commented Mar 17, 2014 at 18:29
  • \$\begingroup\$ I suppose you could use anchors instead, but more importantly it would require preg_quote() as well :) \$\endgroup\$ Commented Mar 18, 2014 at 0:49