Search This Blog

Loading...

Tuesday, November 8, 2011

How to check if string contains substring PHP

Often, we see two approaches for this. One option is to use the strpos PHP function. The following example shows how this is used:
<?php
$pos = strpos($haystack,$needle);
if($pos === false) {
 // string needle NOT found in haystack
}
else {
 // string needle found in haystack
}
?>

0 comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails