[英]PHP regex to replace links with some tokens
我正在查看一些嵌入了音頻播放鏈接的 HTML,如下所示:
...<input type="button" onclick="return play('filename', 'title');" class="playlink" />...
我正在嘗試以編程方式用這種格式的令牌替換它:
{a:filename:title}
但有些事情不正常。 有人可以看一下嗎:
<?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;
?>
我讓它像這樣工作:
$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.