I have this code that strips all HTML tags except for <img>
and <p>
:
<?php
$item->core_body =strip_tags( $item->core_body, '<img><p>');
?>
Because my $item->core_body
contains several <img>
tags, I want to add another condition: I only want to keep the first <img>
tag and strip out all the following ones.
Based on the answer:
<?php
$item->core_body =str_replace('<img','<***',$item->core_body,1);
$item->core_body =strip_tags( $item->core_body, '<img><p>');
$item->core_body =str_replace('<***','<img',$item->core_body,1);
?>