Cap'n Refsmmat Posted July 9, 2005 Author Posted July 9, 2005 I'll see if I can implement <table> with bbcode instead. Should require a bit of regex as well, and allow me to make all < and > to < and >.
Cap'n Refsmmat Posted July 13, 2005 Author Posted July 13, 2005 All right. More questions. Could you change these regexps from eregi to pregi? I hear preg_ functions are faster. $article_text = eregi_replace("\[url=([^(javascript)][^\[]+)\]([^\[]+)\[/url\]","<a href=\"\\1\" target=\"_blank\">\\2</a>", $article_text); $article_text = eregi_replace("\[url\]([^(javascript:)][^\[]+)\[/url\]","<a href=\"\\1\" target=\"_blank\">\\1</a>", $article_text); (working on bbcode tables at the moment)
Aeternus Posted July 14, 2005 Posted July 14, 2005 $article_text = preg_replace("#\[url=([^(?:javascript)][^\[]+)\]([^\[]+)\[/url\]#i","<a href=\"\\1\" target=\"_blank\">\\2</a>", $article_text); $article_text = preg_replace("#\[url\]([^(?:javascript:)][^\[]+)\[/url\]#i","<a href=\"\\1\" target=\"_blank\">\\1</a>", $article_text); Seems you simply needed to include the delimiters at the beginning and end of the regex pattern, and the 'i' modifier to ensure case sensitivity. One thing to note is that [^(?:javascript)] and [^(javascript:)] in both situations (eregi and preg) only prevent the first character after the being j,a,v,a,s,c,r,i,p,t or : (depending on which one). While this does prevent the first word being javascript (as the first letter would have to be J), it also prevents things such as [ url=joako.net ]dfsf[ /url ] or [ url ]joako.net[ /url ] which based on the fact that your not forcing people to have http:// at the beginning seems to suggest SHOULD be valid (but arent). Just thought i'd mention it. Also, the first letter cant be 'j' but it can be a space followed by 'j' which will still work in allowing javascript into the url so you may want to consider revising the regex. $article_text = preg_replace("#\[url=(?!\s*javascript:)([^\[]+)\]([^\[]+)\[/url\]#i","<a href=\"\\1\" target=\"_blank\">\\2</a>", $article_text); $article_text = preg_replace("#\[url\](?!\s*javascript:)([^\[]+)\[/url\]#i","<a href=\"\\1\" target=\"_blank\">\\1</a>", $article_text); The code above SEEMS to work for what I'm assuming your trying to do.
Cap'n Refsmmat Posted July 14, 2005 Author Posted July 14, 2005 Indeed it does work. Thanks. However, if someone forgets the http:// part, then the URL becomes relative to the script and it gets rather messy. Do you think I ought to require http:// or just auto-replace? (have one regex for with, one for without)
Aeternus Posted July 14, 2005 Posted July 14, 2005 Auto-Replace sounds good (sounds nicer for the user anyways). Up to you though
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now