Thread: inStr Function
View Single Post
Old 05-10-2006, 10:08 PM   PM User | #1
xanderman
New Coder

 
Join Date: May 2006
Location: Pennsylvania, USA
Posts: 31
Thanks: 0
Thanked 4 Times in 4 Posts
xanderman is an unknown quantity at this point
Arrow inStr Function

well, i've found this useful for many things so i figured i'd post it

PHP Code:
function inStr ($needle$haystack)
{
  
$needlechars strlen($needle); //gets the number of characters in our needle
  
$i 0;
  for(
$i=0$i strlen($haystack); $i++) //creates a loop for the number of characters in our haystack
  
{
    if(
substr($haystack$i$needlechars) == $needle//checks to see if the needle is in this segment of the haystack
    
{
      return 
TRUE//if it is return true
    
}
  }
  return 
FALSE//if not, return false

Format for using.
PHP Code:
if(inStr("CodingForums""The best site ever is CodingForums"))
{
  echo 
"CodingForums is in this string";

xanderman is offline   Reply With Quote