Stripping the <p> tag

Sometimes when getting the contents of a field, you might find unwanted tags around your content. If you simply want the string inside the tags, you can use $content=strip_tags($content);.

However, this will strip all tags. In the event you have content like <p><b>my hot code load</b></p>, and you want to keep the bold tags, you can simply use $content=strip_tags($content, '<p>'); instead.

For example, I integrated the Swiper module for my homepage. But I wanted the contents of the #swiper_content field as plain text. Even when setting the field to the plain text format, the output from my block--swiper.tpl.php file was still giving me <p>/sites/all/themes//codethenode/images/myimage.png</p>. So I used php's strip_tags() function with the <p> parameter to solve my problem.

    <?php
     
foreach ($variables['elements']['#swiper_content'] as $content):
       
$content = strip_tags($content, '<p>');
   
?>

    <div class="swiper-slide-nid-<?php print $node_id;?> swiper-slide cover" style="background-image: url(<?php print $content; ?>)"></div>
    <?php endforeach; ?>