Jump to content

exact search


phorcon3

Recommended Posts

<?php
$test = 'Online Store';

if(ereg('Store',$test))
{
echo 'yes';
}
else
{
echo 'no';
}

?>

 

this should actually display no.. because i want it to be an exact result.. how can i do this? ereg obviously doesnt do the trick:(

Link to comment
Share on other sites

$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
Share on other sites

<?php
$test = 'Online Store';

if(ereg('^Store$',$test))
{
echo 'yes';
}
else
{
echo 'no';
}

?>

or just

<?php
$test = 'Online Store';

if($test == 'Store')
{
echo 'yes';
}
else
{
echo 'no';
}

?>

Link to comment
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
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.