Jump to content


Photo

[resolved] Contains


  • Please log in to reply
2 replies to this topic

#1 gerkintrigg

gerkintrigg
  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 23 August 2006 - 09:10 AM

Hi!
I wondered what the best function, command line (or whatever else you want to call it) I should use to determine if a string contains another string.

so for example I need to know what the "contains" below needs to be changed to:

<?php 
if ($string_1 contains $string_2){
//do something;
}
?>

Thanks for your help.
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 August 2006 - 09:18 AM

$a = "thisisfoo";
$b = "foo";
if (strstr($a,$b)) {
  echo $b." found in ".$a;
}


#3 gerkintrigg

gerkintrigg
  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 23 August 2006 - 09:23 AM

Nice and easy..
Thanks very much.
I wan't sure what to search for on php.net, but I'll not be forgetting that!
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users