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

时间:2016-04-07 07:14:38

标签: php html

我有一个像

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

我想从中删除img-responsive类。怎么样?

4 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

在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');

答案 2 :(得分:0)

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

答案 3 :(得分:-1)

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

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