我的输入字符串是
$center="[{video('whats-new/reaction-vid1.jpg')} width=\"580\" height=\"326\" alt=\"\" video=\"Zb36h4K2IKQ\"]";
$pattern="/\[{video\('([a-zA-Z0-9\/\-\_]+)'\)}\s+(width|height|alt|video)=\"[^\"]+\"\]/";
if(preg_match($pattern,$center,$matches)){
print_r($matches);exit;
}
然而它不起作用。基本上我想要宽度,高度,alt和视频的额外属性。我已经尝试了半个小时。谁能指出我正确的方向?
答案 0 :(得分:0)
<?php
$center="[{video('whats-new/reaction-vid1.jpg')} width=\"580\" height=\"326\" alt=\"\" video=\"Zb36h4K2IKQ\"]";
$pattern="~video\('\K[^']*|(?:width|height|alt|video)=\"\K[^\"]*~";
preg_match_all($pattern, $center, $matches);
print_r($matches);
?>
输出:
Array
(
[0] => Array
(
[0] => whats-new/reaction-vid1.jpg
[1] => 580
[2] => 326
[3] =>
[4] => Zb36h4K2IKQ
)
)