【发布时间】:2017-06-08 07:47:41
【问题描述】:
我有一个问题,看起来很简单,但是谁给我带来了一些问题。
我有一个文本字符串,它可以包含多个 html 标记、段落和链接(文本链接和/或 html 链接)。我想解析内容,检测带有特定 URL 的链接,并且仅在这种情况下,在 url 中应用跟踪参数。
示例:我只想在以 google.com 开头的网址上添加参数。
$string = 'This is the content... <a href="yahoo.com">Yahoo</a> - <a href="google.com">This one will be surcharged with ?tk=test</a> and direct links too : google.com";
我该怎么做?我尝试使用正则表达式,但它不起作用。我尝试使用 preg_replace,但 URL 可以有多种形式(是否使用 http,不同的 tld 等)。
谢谢!!!
【问题讨论】:
标签: php regex parameters preg-replace