[英]PHP regex to replace links with some tokens
I'm looking at some HTML that has embedded audio-playback links like that:我正在查看一些嵌入了音频播放链接的 HTML,如下所示:
...<input type="button" onclick="return play('filename', 'title');" class="playlink" />...
I'm trying to programmatically replace that with tokens in this format:我正在尝试以编程方式用这种格式的令牌替换它:
{a:filename:title}
But something's not working right.但有些事情不正常。 Could someone look at it:
有人可以看一下吗:
<?php
$src = 'aaaaa<input type="button" onclick="return play(\'hellofile\', \'hellotitle\');" class="playlink" />bbbbb';
$t = preg_replace('#<input\ type="button"\ onclick="return play(\'(.*?)\',\ \'(.*?)\');"\ class="playlink"\ />#us', '{a:${1}:${2}}', $src);
echo $t;
?>
I got it to work like this:我让它像这样工作:
$src = 'aaaaa<input type="button" onclick="return play(\'hellofile\', \'hellotitle\');" class="playlink" />bbbbb';
$rgx = '#<input type="button" onclick="return play\(' . "'(.*?)', '(.*?)'" . '\);" class="playlink" />#u';
$t = preg_replace($rgx, '{a:${1}:${2}}', $src);
echo "$t\n";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.