...

View Full Version : Simple eregi_replace problem



Alux
01-11-2010, 11:44 PM
I *suck* at writing replaces with variables - the syntax boggles my mind, so I was hoping someone here could help with this simple problem.

Due to my laziness, on my new site, i've got an autolink function and a bbocde function - seems like no problem, I got the autolink to convert into BBCode which the BBCode parser then parses. however, when I type the following bbcode:


[ url=http://test.com]Test[/url]
*it's supposed to be without the space, for some reason CODE tags parse it if I don't add in the space*

This is the outcome:


[ url=[ url=http://test.com]http://test.com[/url]]Test[/url]
*it's supposed to be without the space, for some reason CODE tags parse it if I don't add in the space*

Can someone *please* write me a quick eregi replace which would change that (and all other URL bbcodes in that fashion), to this:

[ url=http://test.com]Test[/url]
*it's supposed to be without the space, for some reason CODE tags parse it if I don't add in the space*

JAY6390
01-12-2010, 12:11 AM
First rule is do NOT use eregi. It's deprecated as of 5.3.0 and completely removed in PHP6 onwards. The magical function you need is preg_replace

$result = preg_replace('%\[\s*url\s*=\s*([^\]]+?)\s*\](.*?)\[\s*/\s*url\s*\]%', '<a href="$1">$2</a>', $subject);

Alux
01-12-2010, 12:27 AM
I will start using preg, thanks, but that's not quite what I was after. i was looking to fix my URL tags, not add them. I just want to replace

The URL I'm linking to]The text that describes the link[/url]

with

The text that describes the link



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum