|
-
Mar 25th, 2004, 06:56 PM
#1
Thread Starter
Frenzied Member
preg_replace problem [resolved]
I am such a regex noob it is not even funny. I have found this function to covert BBcode to HTML, but I found a problem.
If I do this, then it makes the URL like it should and puts the words 'Other Text' after the link like you would exprect.
Code:
[ url=http://blah.com]balh[/url] Other Text
'<a href="http://blah.com target="_blank">blah</a> Other text"
If I do this, the 2 links get merged together.
Code:
[ url=http://blah.com]balh[/url] Other Text [ url=http://blah2.com]blah2[/url]
'<a href="http://blah.com" target="_blank">balh[/url] Other text [ url=http://blah2.com]blah2</a>
Here is my code to do the regex stuff
PHP Code:
$texte = preg_replace('/\[url=(.+?)\](.+)\[\/url\]/i','<a href="\\1" target="_blank">\\2</a>',$texte);
**edit, I had to add the space between [ and url because vbforums was making it a link 
Crap, it messes up my preg_replace stuff too.
Last edited by blindlizard; Mar 25th, 2004 at 08:35 PM.
-
Mar 25th, 2004, 08:30 PM
#2
I use this, it works fine with multiple links on the same line:
Code:
<?
$txt = preg_replace("/\[link=(.*?)\](.*?)\[\/link\]/i", "<a href=\"$1\" target=\"new_win\">$2</a>", $txt);
?>
-
Mar 25th, 2004, 08:32 PM
#3
Thread Starter
Frenzied Member
I'll give it a shot, thanks. Any idea what the difference is between (.+?) and (.*?)
-
Mar 25th, 2004, 08:34 PM
#4
Thread Starter
Frenzied Member
It works!!!! You rock! Maybe some day I will try to understand regular expressions
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|