morphboy23 Posted July 7, 2007 Share Posted July 7, 2007 So I want to do this: have text with URL tags in brackets (like [ URL]address[ /URL] and turn it into a link I'm using preg_replace('/\[url\](.*)\[\/URL\]/', '<a href="$1" target="_blank">$1</a>', $text); This works fine if there is just 1 link that is in the $text, but if I have 2 like: check [ URL]something.com[ /URL] and also [ URL]somethingelse.com[ /URL] then it matches the very first [ URL] and the very last [ /URL] making the whole line one giant link with a screwed up address is there any way to get it to work how I want it? *note there shouldnt be spaces in the tags, I did that because these forums were actually parsing them Quote Link to comment https://forums.phpfreaks.com/topic/58812-solved-simple-url-parser/ Share on other sites More sharing options...
sasa Posted July 7, 2007 Share Posted July 7, 2007 try $text=preg_replace('/\[url\]([^[]*)\[\/URL\]/', '<a href="$1" target="_blank">$1</a>', $text); Quote Link to comment https://forums.phpfreaks.com/topic/58812-solved-simple-url-parser/#findComment-291832 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.