Hi My name is Gustavo,

i recently started to code some pages with php.

one of the challenges i have come up with is how do i find a particular string withing a string variable.

for example, lets say i have this string:
$string = 'wallpaperama has cool and amazing wallpapers';

so lets say for example that i want to check if the $string variable contains the word 'wallpaperama'

as humans, its obvious that it does because you can see it. but i want my PHP script to catch it for me.

i found two ways to do it with two functions in php, here they are:

strpos() = string position
and
strstr() = Find first occurrence of a string

gathering from some of my replies here, i guess strpos is better

so these are some examples on how i used these functions:

Example 1. In this example, im going to use the strpos() function to lookup my string, and it should find it.
$string = 'wallpaperama has cool and amazing wallpapers';
$find = 'wallpaper';

if(strpos($string, $find) ===false){
echo '<b>strpos()</b><BR>NO - Did not find <u style="color:red;">'.$find.'</u> in <b>'.$string.'</b>';
}else{
echo '<b>strpos()</b><BR>YES - Found <u style="color:green;">'.$find.'</u> in <b>'.$string.'</b>';
}
OUTPUT:
strpos()
YES - Found wallpaper in wallpaperama has cool and amazing wallpapers

Example 2: In this example, im going to use the strpos() function to lookup my string, and it SHOULD NOT find it.
$string = 'wallpaperama has cool and amazing wallpapers';
$find = 'buzz';

if(strpos($string, $find) ===false){
echo '<b>strpos()</b><BR>NO - Did not find <u style="color:red;">'.$find.'</u> in <b>'.$string.'</b>';
}else{
echo '<b>strpos()</b><BR>YES - Found <u style="color:green;">'.$find.'</u> in <b>'.$string.'</b>';
}
OUTPUT:
strpos()
NO - Did not find buzz in wallpaperama has cool and amazing wallpapers

Example 3. In this example, im going to use the strstr() function to look up my string, and it should find it.
$string = 'wallpaperama has cool and amazing wallpapers';
$find = 'wallpaperama';

if(strstr($string, $find) ===false){
echo '<b>strstr()</b><BR>NO - Did not find <u style="color:red;">'.$find.'</u> in <b>'.$string.'</b>';
}else{
echo '<b>strstr()</b><BR>YES - Found <u style="color:green;">'.$find.'</u> in <b>'.$string.'</b>';
}
OUTPUT:
strstr()
YES - Found wallpaperama in wallpaperama has cool and amazing wallpapers

Example 4: In this example, im going to use the strstr() function to lookup my string, and it SHOULD NOT find it.
$string = 'wallpaperama has cool and amazing wallpapers';
$find = 'buzz';

if(strstr($string, $find) ===false){
echo '<b>strstr()</b><BR>NO - Did not find <u style="color:red;">'.$find.'</u> in <b>'.$string.'</b>';
}else{
echo '<b>strstr()</b><BR>YES - Found <u style="color:green;">'.$find.'</u> in <b>'.$string.'</b>';
}
OUTPUT:
strstr()
NO - Did not find buzz in wallpaperama has cool and amazing wallpapers

so as you can see, you can find any string you want within another string.

hope that help. and thanks for your comments. I am from El Salvador. Its a small country in Central America. So i apologize if my English is not perfect.