0

I search for custom HTML tags with:

$match = preg_replace_callback("/<tag>(.*)<tag>/", function ($key) {
    $result = getTxt($key[1]);

    return $result;
}, $buffer);

It works when input is:

Abc <tag>1<tag> efg

But why it returns null on:

Abc <tag>2<tag> ef <tag>3<tag> h

I've tried to group nongreedy ending tag: /$tag(.*)($tag?)/ with same result.

1
  • Since when was a (?:X|H)TML tag ever closed by another opening tag? Commented May 5, 2014 at 20:13

1 Answer 1

2

You need to make the .* non greedy via .*?

/<tag>(.*?)<tag>/

Say $tag is <tag>, that means $tag? becomes <tag>? which captures <tag and <tag>

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.