[英]PHP regular expression returns blank array
Problem : I need u69ruczh as output this from below code
问题:我需要u69ruczh作为以下代码的输出
$string = '<a data-mce-href="{{file:u69ruczh}}" href="{{file:u69ruczh}}">pptexamples.ppt</a>';
Generated output : 产生的输出:
Array ( [0] => Array ( ) ) 数组([0] =>数组())
I have tried below code : 我试过下面的代码:
$string = '<a data-mce-href="{{file:u69ruczh}}" href="{{file:u69ruczh}}">pptexamples.ppt</a>';
$url = preg_match_all('/href=[\{\{file:(.*?)\}\}]/', $string, $match);
print_r($match);
Please assist me where did it goes wrong 请协助我哪里出错了
If this format is standard this solution should also get you the desired output: 如果此格式是标准格式,则此解决方案还应该为您提供所需的输出:
$string = '<a data-mce-href="{{file:u69ruczh}}" href="{{file:u69ruczh}}">pptexamples.ppt</a>';
$arr = explode(":",$string);
$substr = $arr[1];
$subarr = explode("}",$substr);
$finalstr = $subarr[0];
echo $finalstr;
// Output: u69ruczh
只需使用以下正则表达式即可完成。
$url = preg_match_all('/file\\:([a-zA-Z0-9]+)/', $string, $match);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.