CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Substitute codes to html

 



jessma
New User

Aug 4, 2003, 8:29 AM

Post #1 of 4 (3472 views)
Substitute codes to html Can't Post

I'm new to both regexp and perl, and I've really tried to find a solution to this, but I couldn't find any.

I'm writing a forum and I don't want the users to be able to use html. So far, so good, I've got that to work. Although I still want them to be able to post a (or several) link or picture, with the help of special codes, such as:

Code
[url:www.aplace.com]a place (a end here which I can't get to show)

and then convert them into an ordinary a href-tag. Many forum, like this one, use this.

Any ideas someone?


davorg
Thaumaturge / Moderator

Aug 5, 2003, 1:08 AM

Post #2 of 4 (3466 views)
Re: [jessma] Substitute codes to html [In reply to] Can't Post

Something like this perhaps (untested)...

Code
$text =~ s|\[url:(.*?)](.*?)\[endurl]|<a href="$1">$2</a>|;


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


jessma
New User

Aug 5, 2003, 2:29 AM

Post #3 of 4 (3465 views)
Re: [davorg] Substitute codes to html [In reply to] Can't Post

Smile Thank you! It worked!!


Paul
Enthusiast

Aug 5, 2003, 3:22 AM

Post #4 of 4 (3463 views)
Re: [davorg] Substitute codes to html [In reply to] Can't Post

Better to use ([^\[]+) instead of (.*?) seeing as it's quicker and a URL shouldn't have any occurance of [ in it.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives