Jump to content

[SOLVED] search a word in a string


ravi181229

Recommended Posts

Hi there,

I want to search a word in a string.

In my application, user will post embed link. I will fetch 'site names' from database and search database value (site names) in the user posted values(embed link).

 

for example:

$word = "abcd.com";

$string = "<embed src="abcd.com" width="550" height="400"></embed>";

 

I want to search $word in $string.

 

Need help.

 

Thanks & Regards,

Ravi

Link to comment
https://forums.phpfreaks.com/topic/117754-solved-search-a-word-in-a-string/
Share on other sites

So you're just tring to find out if $word is in $string? Use strpos:

 

<?php
$word = "abcd.com";
$string = '<embed src="abcd.com" width="550" height="400"></embed>';
if(strpos($string,$word) !== FALSE){
echo $word.' occurs in the string';
}else{
echo $word.' does not occur in the string';
}
?>

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.