Removing p tags from around img tags

4 posts by 2 authors in: Forums > CMS Builder
Last Post: April 26, 2010   (RSS)

By dsternalski - April 25, 2010

Hi,

I'm trying to remove p tags from img tags. The code I have is:

<div class="topFeature">
<?php
$content = $featureRecord['content'];
$regExp = "/<p>.*?(<img.*?)<\/p>/";
preg_match($regExp, $content, $aImg);
echo $aImg[1];
echo $content;?>
</div>

This works to a point, but it duplicates the image.

Any suggestions would be highly greatful!

Thanks.

Re: [dsternalski] Removing p tags from around img tags

By gkornbluth - April 25, 2010

Hi dsternalski,

I don't know if this will help, but here's a short excerpt from my CMSB Cookbook http://www.thecmsbcookbook.com on how to remove<p> tags. It might be a simpler approach.

<!-- remove leading <p>, do this _before_ displaying field value -->
<?PHP $record['yourfieldname'] = preg_replace("/^\s*<p>/i", "", $record['yourfieldname'] ); ?>


Hope it points you in a good direction.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Removing p tags from around img tags

By dsternalski - April 26, 2010

Hi, this worked thanks.