Jump to content

[SOLVED] Trimming a string


Fabis94

Recommended Posts

This worked for me:

 

<?php
function tagStripReplace($content){
return preg_replace("~<a(w*[^>])*>.+?</a>~", '', $content);
}
echo tagStripReplace("<p>I like pizza</p><a href=\"aasdf\">Link</a> this is a <b>link</b>");
?>

 

its a modification of this code: http://beta.phpsnips.com/snippet.php?id=38

I know the topic is solved and all (also didn't realize you wanted to remove divs too) but...

 

I modified my code to remove divs as well. It is shorter that the above link...

If you decided to do this (or even read this) let me know how it works for you!

 

<?php
function tagStripReplace($content){
   return preg_replace("~<(a|div)(w*[^>])*>.+?</(a|div)>~", '', $content);
}
echo tagStripReplace("<div>I like pizza</div><a href=\"aasdf\">Link</a> this is a <div class=\"div\"><b>link</b></div>");
?>

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.