获取a href链接并使用regex将其添加到变量中


take a href links and add it to variables using regex

php和regex中的im new。

我有来自旧应用程序的html代码:

$oldlinkshtml = "<li class="active"><a href="www.example.com?page=1">Previous</a></li>";
// desired output
$oldlinksvar = "";
echo $oldlinksvar;

我想删除$oldlinkshtml中的所有html标记,只取"www.example.com?page=1"并将其添加到$oldlinksvar中。我如何使用regex来做到这一点?请帮帮我。

preg_replace('/<a(.*?)href="([^"]*)"(.*?)>/','<a $1 href="http://new.href/?old_url=$2" $3>',$text);


输入:<li class="active"><a href="www.example.com?page=1">Previous</a></li>
输出:<li class="active"><a href="http://new.href/?old_url=www.example.com?page=1" >Previous</a></li>