0

When I moved to a new server, eregi function generates too many errors. I like to use preg_replace instead of eregi function.

Here is my block of code:

if($rstate && !$rcity && !eregi("outside",$rstate)){
$h1title=str_replace('DDD',$tsstate,str_replace('XXX',$tsstate,$pagetitlet));
echo str_replace('DDD',$tsstate,str_replace('XXX',$tsstate,$pagetitlet));

I changed it to:
if($rstate && !$rcity && !preg_replace("outside",$rstate)){
$h1title=str_replace('DDD',$tsstate,str_replace('XXX',$tsstate,$pagetitlet));
echo str_replace('DDD',$tsstate,str_replace('XXX',$tsstate,$pagetitlet));

But it is looking for another value. How do I add the third parameter for preg_replace to get it worked?

Thanks.

1

1 Answer 1

0

You don't need to use a regex for this test, use strpos instead:

if ($rstate && !$rcity && strpos($rstate, "outside")===false) {
    $h1title = str_replace('DDD', $tsstate, str_replace('XXX',$tsstate,$pagetitlet));
    echo str_replace('DDD', $tsstate, str_replace('XXX',$tsstate,$pagetitlet));
    ...
}

Note that the regex function you are looking for is preg_match

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.