0

I want replace in my file all tags "<_tag_>" with "".
I've tried this solutions:

  1. $_text = preg_replace('<\_\s*\w.*?\_>', '', $_text);
    But I replace "<_tag_>" with "<>"

  2. $_text = preg_replace('<\_(.*?)\_>', '', $_text);
    But I replace "<_tag_>" with "<>"

How can I also select angle brackets?

1 Answer 1

1

It could be

<_.+?_>
# <_, anything lazily afterwards, followed by _>

In PHP:

$string = preg_replace('~<_.+?_>~', '', $string);

As in

<?php
$string = "some <_tag_> here";
$string = preg_replace('~<_.+?_>~', '', $string);
echo $string;
# some  here
?>

See a demo on ideone.com.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.