replace <h2> tags before strip_tags

44 Views Asked by At

I'm trying to replace the <h2> and </h2> tag from a string this way but it's not working:

    $desc = get_post_meta($post_id , 'desc', true);
    
    preg_replace("/<h2>/", '', $desc);
    preg_replace("/</h2>/", ' - ', $desc);

Then I like to the strip all other tags this way strip_tags($desc)

1

There are 1 best solutions below

0
btgen On

Do it this way:

    $trash_h2_tags = array("<h2>", "</h2>");
    $desc = str_replace($trash_h2_tags, '', $desc);