Jump to content

exact search


phorcon3

Recommended Posts

$search_term="rohan";
$string="rohan shenoy was here";
if($search_term==$string)
{echo "match found";}
else
{echo "Match not found";}

 

Hope this is the way you expected it.

 

ereg or preg functions are not for this purpose anywayz!

You can try using strpos() too if you find occurrence of an exact phrase within a string.

Link to comment
https://forums.phpfreaks.com/topic/104723-exact-search/#findComment-535998
Share on other sites

i have to use regex b/c im runnin arrays and its lookin for a perfect match? i guess.... ...thanks sasa ...that does it;)

 

Why does it have to matter if its an array or not:

 

<?php
$arr = array('php', 'mysql', 'html');
foreach($arr as $val){
    if($arr == 'php'){
        echo 'My array has got php in it.';
    }
}
?>

 

or even better

<?php
$arr = array('php', 'mysql', 'html');
if(in_array('php', $arr)){
    echo 'My array has got php in it.';
}
?>

 

It is looking for a perfect match in an array. Whats the deal with regex then!!!

Link to comment
https://forums.phpfreaks.com/topic/104723-exact-search/#findComment-536482
Share on other sites

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.