mraza Posted November 18, 2009 Share Posted November 18, 2009 Hi i am trying to parse content of page, what i am having problem is if i have a word like this; <a href="foo.com">Click...Ere</a> i could not pass it through on end result i get something like this [url]Click...Ere[/url] means the word will display like surround url tag not actully getting the hyperlink. please any help what i am missing here is the complete code: '~<img\b[^>]+\bsrc\s?=\s?([\'"])(.*?)\1[^>]*>~is' => '[img=$2]', '~<b\b[^>]*>(.*?)</b>~is' => '[b]$1[/b]', '~<a(.*?)>(.*?)<\/a>~is' => '[url]$2[/url]', Thanks Quote Link to comment Share on other sites More sharing options...
mraza Posted November 18, 2009 Author Share Posted November 18, 2009 hi i have tried this way but now i dont see url tags but the url is not exactly diplaying please any help. it shows that is a link but it just display Click...Ere in href. '~<a\b[^>]+\bsrc\s?=\s?([\'"])(.*?)\1~is', '[url]$2[/url]', Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 18, 2009 Share Posted November 18, 2009 try this out <?php $str = '<a href="foo.com">Click...Ere</a>'; echo preg_replace('~<a[^>]+href="(.*?)"[\s\b\t]*>(.*?)<\/a>~is', '[url]$1[/url]', $str); ?> Quote Link to comment Share on other sites More sharing options...
mraza Posted November 18, 2009 Author Share Posted November 18, 2009 Thanks for the reply its working when i run its alone but when i use it in array, here i am also having images with link to them so when its parsed the image will disappear and the link will appear if i use this code: $replace = array( // image and bold bbc code escaped '~<img\b[^>]+\bsrc\s?=\s?([\'"])(.*?)\1[^>]*>~is' => '', '~<b\b[^>]*>(.*?)</b>~is' => '[b]$1[/b]', // This is your code if i add image will not display as a // link but that will also become a hyper link '~<a[^>]+href="(.*?)"[\s\b\t]*>(.*?)<\/a>~is'=> '[url ]$1[/url]' ); Thanks for any help Quote Link to comment Share on other sites More sharing options...
mraza Posted November 18, 2009 Author Share Posted November 18, 2009 hi i tried this and it worked: '~<a[^>]+href="(.*?)"[\s\b\t]*>(.*?)<\/a>~is'=> '[url=$1]$2[/url]' but now the problem is the link become like this how to remove that extra " target="_blank ..thanks : http://foo.html" target="_blank Quote Link to comment Share on other sites More sharing options...
mraza Posted November 18, 2009 Author Share Posted November 18, 2009 or if it is possible it will take the words " target="_blank and replace it to target="_blank" Thanks Quote Link to comment Share on other sites More sharing options...
cags Posted November 18, 2009 Share Posted November 18, 2009 Not tested as you didn't really give a full example of what you require, but I think this is along the lines of what your after... $pattern = '~<a[^>]+href=("|\')([^\1]*?)\1[^>]*>(.*?)</a>~is'; $replace = '[url=$2]$3[/url]'; Quote Link to comment Share on other sites More sharing options...
mraza Posted November 18, 2009 Author Share Posted November 18, 2009 Thank you cags i was exactly looking for that but it come in my mind if it was possible it will see the words in a tag: " target="_blank and replace it to: target="_blank" i dont wants to use str_ireplace if could be done via expression. but if not that's ok, it just come in mind if it could be via expression. Edit: and btw Congrats for guru badge you deserved it you are always a big help . Thanks 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.