preg_replace:正则表达式不起作用

<h1>title 1</h1 w:id="0"/><p>content</p><h1>title 2</h1 w:id="1"/>...

I want to replace w:id="0"/ from </h1 w:id:="0 or 1 ect "/>

I use this code:

preg_replace("</h1 (.*?)>",'',$html)

But it doesn't work anymore

You are missing the delimiters on your regex.

A regex needs a 'starting mark' and a similar 'finishing mark', so PHP can interpret it's content as the match, with all it's flags.
Without the recognized delimiters, it's impossible to diferenciate between simple text and a regex.

Try this regex:

@</h1 (.*?)>@

Or:

~</h1 (.*?)>~

PHP supports a few more delimiters, like <> and /.


As a side note, I would suggest the following regex:

~</h1( [^>]+)?>~i

try this

preg_replace("/<\/h1 (.*?)>/i",'</h1>',$html);