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); ?> Link to comment https://forums.phpfreaks.com/topic/56698-preg_replace-question/ 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> Link to comment https://forums.phpfreaks.com/topic/56698-preg_replace-question/#findComment-280090 Share on other sites More sharing options...
jammmet Posted June 25, 2007 Author Share Posted June 25, 2007 Thank you kind sir Link to comment https://forums.phpfreaks.com/topic/56698-preg_replace-question/#findComment-281886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.