Jump to content

Stripping custom tags from code?


delphi123

Recommended Posts

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

{ 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?

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.