使用php从html字符串中删除特定的类


remove specific class from html string using php

我有一个类似的字符串

$string = '<img class="img-responsive animate scale animated" src="image/catalog/blocks/about-banner.jpg" alt="">';

我想从中删除img-responsive类。如何删除?

试试这个:$string = str_replace('img-responsive', '', $string);

在Php中,您可以使用str_replace函数,如下所示:

$string = '<img class="img-responsive animate scale animated" src="image/catalog/blocks/about-banner.jpg" alt="">';
$new_string = str_replace('img-responsive', '' , $string);

此外,在Jquery中,执行以下操作:

$('.animate').removeClass('img-responsive');

您可以在php上找到所有关于replace的函数:http://php.net/manual/en/function.str-replace.php

嘿,你可以在脚本中添加以下代码:

<script>
    $(document).ready(function(){
        $('.animate').removeClass('img-responsive');
    });
</script>