in PHP, how to remove specific class from html tag?

后端 未结 4 885
忘了有多久
忘了有多久 2020-12-15 14:24

given the following string in PHP:

$html = \"

text 1

4条回答
  •  醉梦人生
    2020-12-15 15:02

    using the PHP Simple HTML DOM Parser

    Updated and tested! You can get the simple_html_dom.php include from the above link or here.

    for both cases:

    include('../simple_html_dom.php');
    
    $html = str_get_html("

    text 1

    text 2

    text 3

    text 4

    ");

    case 1:

    foreach($html->find('span[class*="test2"]') as $e)
    $e->class = '';
    
    echo $html;
    

    case 2:

    foreach($html->find('span[class*="test2"]') as $e)
    $e->parent()->innertext = $e->plaintext;
    
    echo $html;
    

提交回复
热议问题