note 104932 deleted from function.strrpos by tularis
| From: | tularis@php.net | Date: | Tue, 10 Jan 2012 20:58:03 +0000 |
| Subject: | note 104932 deleted from function.strrpos by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185555@lists.php.net to get a copy of this message | ||
Note Submitter: Protozoid
----
Generally, with any language that has a functional strpos function you can coin a quality instr
function with relative ease. E.g. Borland Delphi 7 doesn't feature an instr method but
conveniently it had a strpos method. I utilized this to create a nice, little instr snippet. I
won't be posting the code because that'd be somewhat irrelevant, but I will post my PHP
port of the snippet.
<?php
function instr($haystack, $needle) {
$pos = strpos($haystack, $needle, 0);
if ($pos != 0) return true;
return false;
}
?>
Trimmed to near perfection.
Example Usage (Self-explanatory but might as well demonstrate it for the heck of it):
<?php
$var = "bowchickawowwow";
if (instr($var, "chicka")) print "needle found in the haystack!";
function instr($haystack, $needle) {
$pos = strpos($haystack, $needle, 0);
if ($pos != 0) return true;
return false;
}
?>