note 104932 modified in function.strrpos by danbrown

From: Date: Mon, 18 Jul 2011 16:13:31 +0000
Subject: note 104932 modified in function.strrpos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181660@lists.php.net to get a copy of this message
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; } ?> --was-- 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. 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; } ?> http://php.net/manual/en/function.strrpos.php

« previous php.notes (#181660) next »