Jump to content

How to check if text exist in a string?


t_machine

Recommended Posts

I don't want to be annoying or something (because the problem is already solved), but I think it's better to use strpos().

 

From the manual, the strstr() function:

Note:  If you only want to determine if a particular needle  occurs within haystack, use the faster and less memory intensive function strpos() instead.

 

And here's how you do it (allow me to use your example, cmgmyr):

<?php

$string = 'This website is cool';
$find = 'website';

if(strpos($string, $find) !== FALSE){
echo "This has $find in it!";
}else{
echo "This does not have $find in it!";
}

?>

 

 

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.