0

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?

  • 1
    @UglyEddie hmmm... [jquery?](http://www.doxdesk.com/img/updates/20091116-so-large.gif) – Sharky Apr 10 '14 at 06:35
  • The question is why do you want do it? Maybe there is a better solution and yes - jQuery is nice - but not a solution for everything. And obviously not the best solution for someone that tries to change HTML with PHP - looks more like a lack of knowledge. – Jurik Apr 10 '14 at 06:43
  • 1
    Are you simply trying to replace all col-* classes to a single col-md-4 class? – MShah Apr 10 '14 at 06:44

2 Answers2

0

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);
Nambi
  • 11,944
  • 3
  • 37
  • 49
0

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.

Jurik
  • 3,244
  • 1
  • 31
  • 52
  • `getElementsById` ? id is a unique IDentifier. there is no getElement**s**ById and clearly not the way to go – Sharky Apr 10 '14 at 06:55
  • @Sharky holy god - it was a typo/copypaste, thanks! And next time just edit the answer and everything is good. – Jurik Apr 10 '14 at 07:38