Text parsing and replacement. php5
Totally lost on how to do this but figure it's via one or more of the string functions.
Am adding in bbcode tags to an articles management system and so far pretty easy to do bold, underline, strike out, etc.
Having problems getting an article link thing to work.
What I would like to do is tag up titles appearing in articles, then when the article is parsed the software will check if another article exists in the datebase and replace the bbcode with a link to the other article.
Something like
Quote:
Considering the similarities to Miike's [ m ] Imprint [ /m ] one is left with the only conclusion being ....
So "Imprint" is seen as an article title, due to the [ m ] tag (spaces inserted just in case vB's parser does something with them), when it comes time to display this article, the software takes "Imprint" checks if an article of that name exists in the db, if it does then the software replaces the "[ m ] Imprint [ /m ]" with a link to the "Imprint" article, if it doesn't the [ m ] tags are simply removed. Oh and articles can of course have multiple words in their title.
Hopefully that all make's some sort of sense :confused:
Thanks in advance.
Re: Text parsing and replacement. php5
What part are you having trouble with? The tag checking? The tag adding to articles? The tag replacement?
Re: Text parsing and replacement. php5
Quote:
Originally Posted by manavo11
What part are you having trouble with? The tag checking? The tag adding to articles? The tag replacement?
The tag replacement with a url link.
Re: Text parsing and replacement. php5
What do you have so far? Are you using a simple string replace to change the tags to HTML? Regular expressions?
Have a look at this :
http://www.vbforums.com/showthread.p...ar+expressions
Re: Text parsing and replacement. php5
Quote:
Originally Posted by manavo11
Am using the preg_replace function and have bold, italic, and strike-out working but am unsure if I can take the same approach with urls as it will need to search for the title on the database, work out the url extension before converting the tags.
At this stage just toying with the idea, trying to get it to work, and then seeing the impact on a db with a few hundred records.
Re: Text parsing and replacement. php5
You can use the preg_replace_callback() function. You can have your checking code in here. I would advise you do this on input rather than during the display process.