Re: php equivalent to asp's instr()
| From: | DvDmanDT | Date: | Wed, 27 Aug 2003 21:18:59 +0000 |
| Subject: | Re: php equivalent to asp's instr() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-160965@lists.php.net to get a copy of this message | ||
Hmm... Are you sure strpos doesn't work for you? Sure worked for me when I
wanted something like that Otherwise, checkout following:
http://se2.php.net/strings
function instr($needle, $haystack,$case_sensitive=true)
{
return
(($case_sensitive?strpos($needle,$haystack):stripos($needle,$haystack))!==fa
lse);
}
try that, although, that's just from the top of my head, not tested or
anything and it's my pretty bad coding style...
also, take a look at ereg()...
--
// DvDmanDT
MSN: dvdmandt@hotmail.com
Mail: dvdmandt@telia.com
"Chris W. Parker" <cparker@swatgear.com> skrev i meddelandet
news:001BD19C96E6E64E8750D72C2EA0ECEE1AE1D8@ati-ex-01.ati.local...
Hi.
I don't know why but I've had the darndest time trying to find an easy
equivalent of asp's InStr() function in PHP. I know there is
preg_match(), strpos(), and strstr(), but none of them work like I want
them to.
In fact, except for maybe preg_match(), I can't get any of them to work
right.
I want a function that will return true if the string is found, and
false if it is not found.
Like this:*
$needle = "&";
$haystack = "Belle & Sebastian";
if(FoundInString($needle, $haystack))
{
echo "found!";
}
else
{
echo "not found!";
}
Anyone have a function to share?
Thanks,
Chris.
* Anyone catch the Belle & Sebastian show at the Greek Theatre in LA
this past sunday?