You are here: Re: Replacing part of link with regexp « PHP Programming Language « IT news, forums, messages
Re: Replacing part of link with regexp

Posted by Hero Wanders on 08/26/05 14:18

Hello!

> <a href="www.abc.com">ABC</a>
> <a href="www.xyz.com">www.xyz.com</a>
>
> I'm looking for a script that replaces the part within the HTML tag
> (www.abc.com and www.xyz.com) with another link (in my case a
> redirect), without affecting the part with "www.xyz.com: enclosed by
> the tags.

This should work:

<?php

$link = '<a href="http://www.google.com" target="_bla">foobar</a>';
$my_url = 'http://www.example.com/redirect.php?url=$1';

echo preg_replace('/(?<=\<a href\=\")([^\"]+)(?=\")/', $my_url, $link);

?>

Of course $link could be any text containing links.

Greetings,
Hero Wanders

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация