jammmet Posted June 22, 2007 Share Posted June 22, 2007 Hi, I'm new to both php and regular expressions. I need to replace some stuff in a string, but am at a complete loss as to how to do it. Links in my database are entered like this: [[externalLink1]here] and I want it to be transformed to look like this: <a href="externalLink1">here</a> Below is what I have so far - obviously it doesn't work. Can anyone help me out? much appreciated: <?php $src = "Download DirectX from [[externalLink1]here] Download Windows Media Player from [[externalLink2]here]"; $urls[0] = "http://www.microsoft.com/windows/directx"; $urls[1] = "http://www.microsoft.com/windows/mediaplayer"; echo preg_replace ("/\[\[(externalLink.*)\](.*)\]/", $urls, $src); ?> Quote Link to comment Share on other sites More sharing options...
effigy Posted June 22, 2007 Share Posted June 22, 2007 <pre> <?php $src = "Download DirectX from [[http://www.microsoft.com/windows/directx]here] Download Windows Media Player from [[http://www.microsoft.com/windows/mediaplayer]here]"; echo preg_replace ('/\[\[([^]]+)\]([^]]+)\]/', '<a href="\1">\2</a>', $src); ?> </pre> Quote Link to comment Share on other sites More sharing options...
jammmet Posted June 25, 2007 Author Share Posted June 25, 2007 Thank you kind sir Quote Link to comment 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.