Prashant Sharma
Prashant Sharma

Reputation: 148

remove specific class from html string using php

I have a string like

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

I want to remove img-responsive class from it. How?

Upvotes: 0

Views: 513

Answers (4)

Vishnu Sharma
Vishnu Sharma

Reputation: 642

In Php, You can use str_replacefunction as below:

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

Additionally, in Jquery, do like below:

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

Upvotes: 1

Fırat Kocabay
Fırat Kocabay

Reputation: 76

You can find all functions about replace on php : http://php.net/manual/en/function.str-replace.php

Upvotes: 0

vishu
vishu

Reputation: 231

Hey u can just add below code in script:

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

Upvotes: -1

Andrii Mishchenko
Andrii Mishchenko

Reputation: 2694

Try this: $string = str_replace('img-responsive', '', $string);

Upvotes: 2

Related Questions