preg_replace 用于修改 URL
我正在尝试更新数据库中的一些 URL。
以下是我正在处理的主题文本的一部分:
abcd abc(<a href=http://www14.xx.com/banket00/xx.aspx?id=384>abc</a>). abc ab %30-40 abcd. <a href=http://www.xx.edu.it/~xx/xxx.html target=_blank>abc</a> abcd xxx.
(7061, 931, 'xx', 'xx. <a class=''abc'' href=xx.aspx?id=1657 target=right>"xxxx! xxx</a>', 1, NULL, 0, '2005-02-07 17:47:00', 0),
xx <a class=''abc'' href=xx.aspx?id=4340 target=right>xxx</a>''xxx.<br>04 x 2007 : xxxx.com 33000 xxxxxx.', 1, '2007-11-04 18:13:00', 0, '2007-11-04 16:12:00', 0),
(35761, 5257, 'xxxx', '<a href="http://x.org.global-x.com/xxx.aspx?id=5249&jj=1" target=_blank>http://x.org.global-x.com/xxxx.aspx?id=5249&jj=1</a>', 1, '0000-00-00 00:00:00', 0, '2009-03-21 12:08:00', 0),
我想做的是将包含“aspx?id=x”的 URL 更新为
到目前为止,我已经尝试了很多模式,其中一些适用于某些 URL,但我想出的最新表格不起作用:
pattern: /<a[ class='*abc'*]* href=[a-zA-Z\.-_\/:'"]*?\?id=(\d+)"*[ target=[right|_blank]]*>([^<]*?)<\/a>/i
replacement: '<a href="#" onclick="func($1)">$2</a>'
I am trying to update some URLs in the database.
The following is a part of the subject text that I am working on:
abcd abc(<a href=http://www14.xx.com/banket00/xx.aspx?id=384>abc</a>). abc ab %30-40 abcd. <a href=http://www.xx.edu.it/~xx/xxx.html target=_blank>abc</a> abcd xxx.
(7061, 931, 'xx', 'xx. <a class=''abc'' href=xx.aspx?id=1657 target=right>"xxxx! xxx</a>', 1, NULL, 0, '2005-02-07 17:47:00', 0),
xx <a class=''abc'' href=xx.aspx?id=4340 target=right>xxx</a>''xxx.<br>04 x 2007 : xxxx.com 33000 xxxxxx.', 1, '2007-11-04 18:13:00', 0, '2007-11-04 16:12:00', 0),
(35761, 5257, 'xxxx', '<a href="http://x.org.global-x.com/xxx.aspx?id=5249&jj=1" target=_blank>http://x.org.global-x.com/xxxx.aspx?id=5249&jj=1</a>', 1, '0000-00-00 00:00:00', 0, '2009-03-21 12:08:00', 0),
What I am trying to do is to update the URLs that contain "aspx?id=x" into
"'<a href="#" onclick="func(<id_in_url>)"><text_of_link></a>'
"
I have tried many patterns until now and some of them worked for some of the URLs but the latest form I came up with does not work:
pattern: /<a[ class='*abc'*]* href=[a-zA-Z\.-_\/:'"]*?\?id=(\d+)"*[ target=[right|_blank]]*>([^<]*?)<\/a>/i
replacement: '<a href="#" onclick="func($1)">$2</a>'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的链接必须满足什么条件吗?如果没有,我认为它有效:
Is there any condition that your links must fulfill? If not I think it works:
使用:
Use: