Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php删除url但保留锚定_Php_Url_Replace - Fatal编程技术网

php删除url但保留锚定

php删除url但保留锚定,php,url,replace,Php,Url,Replace,我在长文本中有一些链接: <a class="class1" href="https://www.test.com/de/de/products/2018/street/bike/details.html#2"><sup>2</sup></a> 我想删除href,但保留锚点如下: <a class="class1" href="#2"><sup>2</sup></a> URL并不总是相同的

我在长文本中有一些链接:

<a class="class1" href="https://www.test.com/de/de/products/2018/street/bike/details.html#2"><sup>2</sup></a>

我想删除href,但保留锚点如下:

<a class="class1" href="#2"><sup>2</sup></a>

URL并不总是相同的,因此这部分“de/de/products/2018/street/bike/”有所不同。锚的数量也各不相同

这可能吗

非常感谢你的帮助

检查我的钢笔。我使用jquery根据输入选择定义href的值

您将使用attr方法:

$('a#attibute').attr("href", "the url comes here");

希望它能工作

好的,最后这真的很简单

因为我可以删除我使用的代码中的所有HREF

$dateninhalt = preg_replace('/http[\s\S]+?.html/', '', $dateninhalt);
所以从链接来看

<a class="class1" href="https://www.test.com/de/de/products/2018/street/bike/details.html#2"><sup>2</sup></a>


从“http”到“.html”的所有内容,包括这两个字符串,都被零(“”)所取代。

最好总是发布一个问题,并显示您尝试过的内容,或者至少显示您在谷歌搜索过的内容。您可以使用codepen、jsfiddle、etcIf。您不能使用
jquery
尝试值得注意的OP想要的php解决方案-jquery可能在他们的网站上不可用感谢您的快速回答!不幸的是,我需要使用php。使用jQuery很容易,但是这个str_替换的东西让我很难受。