Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.