Roaddoctor Posted November 30, 2012 Posted November 30, 2012 A little advice please... I am wanting to parse my product description to a new page, but stripped of any hyperlinks, while retaining all other html. Is there a better way than this? at the moment I took <?php echo stripslashes($product_info['products_description']); ?> and changed to <?php echo stripslashes(strip_tags($product_info['products_description'],'<p><br><img><b><strong><h2><h3><em><ul><li>')); ?> Is there a more elegant solution? Thanks! -Dave
♥bruyndoncx Posted December 1, 2012 Posted December 1, 2012 use preg_replace function more performant, probably, more elegant, I doubt it ... KEEP CALM AND CARRY ON I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support). So if you are still here ? What are you waiting for ?! Find the most frequent unique errors to fix: grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt
Roaddoctor Posted December 1, 2012 Author Posted December 1, 2012 like this? <?php echo stripslashes(preg_replace('/<a[^>]*>(.*)<\/a>/iU','', $product_info['products_description'])); ?> -Dave
multimixer Posted December 1, 2012 Posted December 1, 2012 Why not use jQuery on the target page? $("a").replaceWith(function() { return $(this).contents(); }); My community profile | Template system for osCommerce - New: Responsive | Feedback channel
burt Posted December 1, 2012 Posted December 1, 2012 If you want to strip the link but keep the text, eg go from <a href="http://www.google.com">google</a> to google use strip_tags .
Roaddoctor Posted December 1, 2012 Author Posted December 1, 2012 Thanks all! As I was reading around on this there was lots of advice to not use regex to parse html... so I was debating which way to go. Burt what you posted is what I had in mind initially. I had not cosidered jquery, but interesting. Always multiple ways to get to the end. Can I consider the syntax in the first post correct? Thanks much for the confirm. -Dave
Recommended Posts
Archived
This topic is now archived and is closed to further replies.