How to rename class ( command in PHP)

Discussion in 'PHP' started by nasi, Jan 3, 2012.

  1. #1
    Hi guys,

    I have script that import data into my website.If I want to replace some class in HTMl,for example: class="add-review"
    I use that command:
    $html = preg_replace('#<a[^>]*class="add-review"[^>]*>.*?</a>#is', '', $html);

    But how can I just rename that class,without replacing it?
    (something like: rename class="add-review" to class="add-rating") I'm not a coder,so excuse my poor language:)

    Thanks to all in advance
    Nasi
     
    nasi, Jan 3, 2012 IP
  2. AlexanderZ

    AlexanderZ Member

    Messages:
    28
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    48
    #2
    
    $html = preg_replace('#(<a[^>]*class=")add-review("[^>]*>.*?</a>)#is', '$1add-rating$2', $html);
    
    Code (markup):
     
    AlexanderZ, Jan 3, 2012 IP
  3. nasi

    nasi Active Member

    Messages:
    135
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Thaaaaaaaaaaaaaanks AlexanderZ!!!You saved me.Thank god for people like you.
     
    nasi, Jan 5, 2012 IP