私は次のものを持っています:
$reg[0] = '`<a(\s[^>]*)href="([^"]*)"([^>]*)>`si';
$reg[1] = '`<a(\s[^>]*)href="([^"]*)"([^>]*)>`si';
$replace[0] = '<a$1href="http://www.yahoo.com"$3>';
$replace[1] = '<a$1href="http://www.live.com"$3>';
$string = 'Test <a href="http://www.google.com">Google!!</a>Test <a href="http://www.google.com">Google!!2</a>Test';
echo preg_replace($reg, $replace, $string);
結果は次のとおりです。
Test <a href="http://www.live.com">Google!!</a>Test <a href="http://www.live.com">Google!!2</a>Test
私は(最初のリンクにある違い)で終わることを目指しています:
Test <a href="http://www.yahoo.com">Google!!</a>Test <a href="http://www.live.com">Google!!2</a>Test
アイデアは、文字列内のリンク内の各 URL を一意の他の URL に置き換えることです。これは、人々が何をクリックしたかを追跡したいニュースレター システム用であるため、URL は「偽の」URL になり、クリックが記録された後に実際の URL にリダイレクトされます。