0

I have this string in PHP

$content="<a some_text> {pr_start} some_text</a> <a other_text>{pr_stop}</a>
          <a some_text> {pr_start} </a> <a some_text> {pr_start} </a>";

I want to replace all the occurrences of the substring

"<a some_text> {pr_start}  some_text</a>"

with text "START" and leave the rest as it is!

The result expected is:

"START <a other_text>{pr_stop}</a> START START"

I used

preg_replace('#<a(.*)({pr_start})(.*)</a>#',"START",$content);

Any idea? Thanks!

1 Answer 1

2

You need to add an ungreedy flag U in your pattern:

preg_replace('#<a(.*)({pr_start})(.*)</a>#U',"START",$content);
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.