私は、いくつかのhtmlコンテンツといくつかのhrefリンクを持つphp変数を持っています。このリンクをキャプチャしてDBに保存し、保存した行のIDに置き換える必要があります(これは、ニュースレターアプリケーションでそのリンクをたどった人の数を追跡するためです)。hrefリンクをキャプチャしてPHPでこれを置き換える方法
基本的には、この例では2つの関数(some_function_to_save_the_links_to_arrayとsome_function_to_save_the_links_to_array)を実行する必要があります。
ありがとうございました!
例:
$var = "<html><body><h1>This is the newsletter</h1><p>Here I have <a href='http://www.google.com'>Some links</a> in the body of this <a href='http://www.yahoo.com'>Newsletter</a> and I want to extract their.</body></html>";
//Here I just no know how to do this, but I need to save http://www.google.com and http://www.yahoo.com to, maybe, an array, and save this array in a mysql db.
some_function_to_save_the_links_to_array;
while (THERE ARE VALUES IN THE ARRAY OF THE LINKS){
save $array['X'] to db //(I already know how to do it, this is not the problem)
$id = last inserted row in db //I know how to do it also
function_to_replace_the_links_for_the_id;
}
echo $var;
And this is the echo:
<html><body><h1>This is the newsletter</h1><p>Here I have <a href='http://www.mysite.com/link.php?id=1'>Some links</a> in the body of this <a href='http://www.mysite.com/link.php?id=1'>Newsletter</a> and I want to extract their.
[要素のhref属性をつかん]の可能な重複(http://stackoverflow.com/questions/3820666/grabbing-the-href-attribute-of-an-a-element) – Gordon
が削除私の答えは、Gordonが提供したリンクの例が優れています。 – Leigh