mysterbx Posted January 30, 2008 Share Posted January 30, 2008 Hello, I searching a lot of messages in these forums but couldnt find a code to replace <a href='http:/links.com'>link< /a> <a href='http:/links2.com'>link2< /a> <a href='http:/links3.com'>link3< /a> <a href='http:/links4.com'>link4< /a> into http://links.com http://links2.com http://links3.com http://links4.com This should be possible... Quote Link to comment https://forums.phpfreaks.com/topic/88550-solved-replace-hyperlinks-with-plain-text/ Share on other sites More sharing options...
PHP Monkeh Posted January 30, 2008 Share Posted January 30, 2008 You want <a href='http://links.com'>link[/url] to be turned in to links or did you mean [url=http://links.com]link[/url] Quote Link to comment https://forums.phpfreaks.com/topic/88550-solved-replace-hyperlinks-with-plain-text/#findComment-453295 Share on other sites More sharing options...
mysterbx Posted January 30, 2008 Author Share Posted January 30, 2008 // nothing here http://links.com // nothing here Quote Link to comment https://forums.phpfreaks.com/topic/88550-solved-replace-hyperlinks-with-plain-text/#findComment-453298 Share on other sites More sharing options...
mysterbx Posted January 30, 2008 Author Share Posted January 30, 2008 just simple text, no hyperlinks http://links.com Quote Link to comment https://forums.phpfreaks.com/topic/88550-solved-replace-hyperlinks-with-plain-text/#findComment-453302 Share on other sites More sharing options...
thebadbad Posted January 30, 2008 Share Posted January 30, 2008 You could use RegEx if you want to extract a bunch of URLs from a string. <?php $string = '<a href="http://link.com/">Link</a> <a href="http://link2.com/">Link2</a> <a href="http://link3.com/">Link3</a> <a href="http://link4.com/">Link4</a>'; preg_match_all('|<a href="(.*?)">|', $string, $matches); print_r($matches[1]); // Array //( // [0] => http://link.com/ // [1] => http://link2.com/ // [2] => http://link3.com/ // [3] => http://link4.com/ //) ?> Quote Link to comment https://forums.phpfreaks.com/topic/88550-solved-replace-hyperlinks-with-plain-text/#findComment-453315 Share on other sites More sharing options...
laffin Posted January 30, 2008 Share Posted January 30, 2008 this is kinda simple as it dun check for anything but what ya have given preg_replace('@<a href=[\'\"]([^\s]+)[\'\"]>.*</a>@im','$1',$body); Quote Link to comment https://forums.phpfreaks.com/topic/88550-solved-replace-hyperlinks-with-plain-text/#findComment-453316 Share on other sites More sharing options...
mysterbx Posted January 30, 2008 Author Share Posted January 30, 2008 umm... i tried both codes, preg replace doesnt work.. and preg_match_all outputs like this Array ( [0] => http://www.exmplae.com/Movies.htm">Movies</a> category on <a href="http://www.exmplae.com/archive-28/01/2008.htm">28/01/2008</a></ul></div><div class='saex'><a target='_blank' href='http://www.exmplae.com/premium-One-Missed-Call--2008--TS.htm'><img src='http://undergroundwarez.info/covers/1313.jpg' alt='example'></a><br><br><div class='dlname'><ul><a target='_blank' href='http://www.exmplae.com/out-free-and-full-tests.htm'>test More Full And Free Movies, Games & Apps!</a></ul></div><br>In this remake of the Japanese horror film Chakushin Ari (2003), several people start receiving voice-mails from their future selves -- messages which include the date, time, and some of the details of their deaths.... Brought to you by http://www.exmplae.com/ ...<br><br><a target='_blank' href='http://www.exmplae.com/premium-One-Missed-Call--2008--TS.htm'>test example</a><br><a target='_blank' href='http://www.exmplae.com/torrent-for-One-Missed-Call--2008--TS.htm'>test example</a><br><br><b>test links</b><br> <a href="http://fileexmple.com/files/85733795/exmplae1.rar [1] => http://fileexmple.com/files/85733563/exmplae2.rar [2] => http://fileexmple.com/files/85733231/exmplae3.rar [3] => http://fileexmple.com/files/85733388/exmplae4.rar [4] => http://fileexmple.com/files/85733323/exmplae5.rar [5] => http://fileexmple.com/files/85733038/exmplae6.rar [6] => http://fileexmple.com/files/85730514/exmplae7.rar [7] => http://fileexmple.com/files/85763910/exmplae8.rar ) is it possible to do this: if href="" contains whitespace/space \s then do not add this link, but if not add it... Quote Link to comment https://forums.phpfreaks.com/topic/88550-solved-replace-hyperlinks-with-plain-text/#findComment-453358 Share on other sites More sharing options...
laffin Posted January 30, 2008 Share Posted January 30, 2008 preg_replace works perfect here, not shure how u tested it. <?php $string = '<a href="http://link.com/">Link</a> <a href="http://link2.com/">Link2</a> <a href="http://link3.com/">Link3</a> <a href="http://link4.com/">Link4</a>'; $string=preg_replace('@<a href=[\'\"]([^\s]+)[\'\"]>.*</a>@im','$1',$string); echo "<pre>$string</pre>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/88550-solved-replace-hyperlinks-with-plain-text/#findComment-453363 Share on other sites More sharing options...
mysterbx Posted January 30, 2008 Author Share Posted January 30, 2008 it works now one last question... is it possible to find only the url, and ignore all target="_blank", target="_new", style="anything", just replace all the <a href> tags and show the links only? now it only works with <a href="anythinghere"> but it wouldnt work with <a style="color:#FFFFFF;" href="anythinghere" target="_blank">... Quote Link to comment https://forums.phpfreaks.com/topic/88550-solved-replace-hyperlinks-with-plain-text/#findComment-453377 Share on other sites More sharing options...
laffin Posted January 30, 2008 Share Posted January 30, 2008 $string=preg_replace('@<a .*href=[\'\"]([^\s]+)[\'\"].*>.*</a>@im','$1',$string); Quote Link to comment https://forums.phpfreaks.com/topic/88550-solved-replace-hyperlinks-with-plain-text/#findComment-453400 Share on other sites More sharing options...
mysterbx Posted January 30, 2008 Author Share Posted January 30, 2008 works like a charm!!! thx a lot! Quote Link to comment https://forums.phpfreaks.com/topic/88550-solved-replace-hyperlinks-with-plain-text/#findComment-453431 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.