delphi123 Posted April 8, 2009 Share Posted April 8, 2009 Hi there, I'm struggling with a simple script that'll strip cusom tags (all contained in { }). These tags are used in news articles, to do things like redirect/display modules etc. On the site frontpage I'm wanting to pull the text through as an intro to articles, but I just want it to display as plain text - that means stripping all html and custom tags before it's brough through (ie everything within < > and { }) I'd appreciate any advice people have on the best way to do this - I've been writing specific php to tackle this: Code: $sbd_start = strpos(strtolower($row->introtext),'{'); $sbd_end = strpos(strtolower($row->introtext),'}',$sbd_start); $sbd_string = substr($row->introtext,$sbd_start,($sbd_end-$sbd_start)); $intro = str_replace($sbd_string,' ',$intro); But I figured there may be a cleverer way (maybe an inbuilt php function that forces data to show only plain text?) Have also tried preg_replace, but could figure out the way to do that efficiently (again, don't know if there's a standard preg_replace snippet gurus use to get rid of all the standard tags? Also saw strip_tags, but (to the best of my knowledge) this only works on html and I can't specify other tags? Any help much appreciated! Link to comment https://forums.phpfreaks.com/topic/153116-stripping-custom-tags-from-code/ Share on other sites More sharing options...
Axeia Posted April 8, 2009 Share Posted April 8, 2009 { and } are plain text. So just combine what you have with the strip_tags function and you're done. You could try writing a big regular expression, but the advantage? 1) Build in functions usually are a ton faster then a regex 2) If you need to adept the code in the future, do you want to decipher your huge regular expression? Link to comment https://forums.phpfreaks.com/topic/153116-stripping-custom-tags-from-code/#findComment-804309 Share on other sites More sharing options...
thebadbad Posted April 8, 2009 Share Posted April 8, 2009 Use strip_tags() for the HTML and this regex for the custom tags: <?php $str = preg_replace('~{[^}]*}~', '', $str); ?> Link to comment https://forums.phpfreaks.com/topic/153116-stripping-custom-tags-from-code/#findComment-804332 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.