Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

What is the best way to strip links from product description?


Roaddoctor

Recommended Posts

Posted

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

Posted

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

Posted

like this?

 

<?php echo stripslashes(preg_replace('/<a[^>]*>(.*)<\/a>/iU','', $product_info['products_description'])); ?>

-Dave

Posted

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

.

Posted

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...