如何将带有属性的标签替换为字符串空?

How i can replace a string from:

"this is a <p id="1" /> text <p id="2" /> of a string"

To:

"this is a <br> text <br> of a string" ?

Shortly i want replace all <p ... /> present in a string with <br>.

update: (just <p ... />)

echo preg_replace("/<p[^\/]*\/>/i", "<br />", 'this is a <p id="1" /> text <p id="2" /> of a string');

You can use preg_replace() along with str_replace()

$newString = preg_replace("/<p[^>]*?>/", "", $yourString); // will remove all starting tag
$addNewLine = str_replace("</p>", "<br />", $newString); // will replace closing tag with <br>

Try it:

<?php
echo preg_replace("<p id=\"d\"/>", "<br>", "this is a <p id=\"1\" /> text <p id=\"2\" /> of a string");
?>

You'll get:

this is a

text

of a string