2

I have this string :

$body = '<a href="/title/tt2034800/?ref_=inth_ov_tt"> The Great Wall</a>';

And i want to remove :

?ref_=inth_ov_tt

From $body .

I test this code and didn't work :

$body = preg_replace('#ref_=(.*?)"#is', '', $body);
1
  • The regex works fine for me. Just add the ? to remove exactly what you want to remove. Commented Feb 19, 2017 at 11:12

1 Answer 1

2

Change your regex pattern to the following:

$body = '<a href="/title/tt2034800/?ref_=inth_ov_tt"> The Great Wall</a>';
$body = preg_replace('#\?ref_=([^"]+)(?=")#i', '', $body);

print_r($body);

The output(as source code):

<a href="/title/tt2034800/"> The Great Wall</a>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks . Worked Fine .

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.