here i have some content with some links .in this code i want to replace all those links with modified links
the Fucction get_web_page
gives me the modified links.
$text='<a href="http://tinyurl.com/2tx">google</a>dfhjksdf sdjfkhdskjf sddsf <a href="http://tinyurl.com/d8r">Microsft.com</a>';
preg_match_all('/<a [^>]*href="?([^">]+)"?>/', $text, $matches, PREG_SET_ORDER);
foreach ($matches as $ht)
{
$new_link=get_web_page($ht[1]);
$new_link=$new_link['url'];
echo $gg=str_replace($ht[1], $new_link, $text);
}
in above code everything is working fine except the foreach loop the loop is repeating the output and in first output only firest link is replaced. in second out only second link is replaced.
the output is like this
<a href="http://www.google.vg/">google</a>dfhjksdf sdjfkhdskjf sddsf <a href="http://tinyurl.com/d8r">Microsft.com</a>
<a href="http://tinyurl.com/2tx">google</a>dfhjksdf sdjfkhdskjf sddsf <a href="http://www.microsoft.com/en-us/default.aspx">Microsft.com</a>
i want it to replace all the links at once and the output should the input $text
with modified links.
can anyone tell me where i am going wrong ?