Jump to content

Recommended Posts

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...

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/
//)
?>

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...

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>";
?>

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">...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.