【发布时间】:2017-04-20 08:28:17
【问题描述】:
我已经得到了一个页面 php 与这一行:
$url = file_get_contents('http://web.com/rss.php');
现在我想替换这个:
<link>http://web.com/download/45212/lorem-ipsum</link>
<link>http://web.com/download/34210/dolor-sit</link>
<link>http://web.com/download/78954/consectetur-adipiscing</link>
<link>http://web.com/download/77741/laboris-nisi</link>...
有了这个:
<link>http://otherweb.com/get-d/45212</link>
<link>http://otherweb.com/get-d/34210</link>
<link>http://otherweb.com/get-d/78954</link>
<link>http://otherweb.com/get-d/77741</link>...
我已经用str_replace 替换了一部分,但我不知道要替换另一部分。
这是我目前所做的:
$url = str_replace('<link>http://web.com/download/','<link>http://otherweb.com/get-d/', $url);
【问题讨论】:
-
那么当你运行 str_replace 时你会得到什么结果?
-
我需要数字。
<link>http://otherweb.com/get-d/</link> <link>http://otherweb.com/get-d/</link> <link>http://otherweb.com/get-d/</link> <link>http://otherweb.com/get-d/</link>... -
看起来它会工作。
-
或者您是否希望它剥离“/45212”之后的信息?
标签: php regex preg-replace preg-match str-replace