用PHP更改html属性[重复]

This question already has an answer here:

I have this HTML code

<div id="meta-8" class="widget col-lg-3 col-md-3 col-sm-12 col-xs-12 widget_meta "><div class="widget-wrap">

What I want to do is... I want to change it using PHP pregreplace, so it become:

<div id="meta-8" class="widget col-md-4 widget_meta "><div class="widget-wrap">

Maybe the code will be like this

$output = preg_replace("RegEx", "col-md-4 widget_meta", $string);

But, I'm not familiar with RegEx.. Could someone help me please?

</div>

You can do like this for regex way but i suggest you to do it with using html parser

$html='<div id="meta-8" class="widget col-md-4 widget_meta "><div class="widget-wrap">';
preg_replace("~(?<=class=")([^"]*)~", "widget col-md-4 widget_meta", $input_lines);

Referring to w3cSchools you can use this easy javascript code:

document.getElementById('meta-8').setAttribute('class','widget col-md-4 widget_meta');

As I said in my comment, I do not know why you want do it - so this is a solution. And I would not use jQuery just to do this. Maybe you could explain more why you want change it with PHP.