字符串的格式是<embed src="/fofa/upload/2014-08/05/5.mp4" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" />这个样子的
请问怎么截取src=“”里面的内容呢,也就是红字部分。求指导啊
------解决方案--------------------
$s=<<<txt
<embed src="/fofa/upload/2014-08/05/5.mp4" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" />
txt;
preg_match('/src="(.+?)"/i', $s, $m);
echo $m[1];
------解决方案--------------------
$s =<<< TXT
字符串的格式是<embed src="/fofa/upload/2014-08/05/5.mp4" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" />这个样子的
请问怎么截取src="..."里面的内容呢,也就是红字部分。求指导啊
TXT;
preg_match_all('/src=([\'"]?)(.+?)\1/is', $s, $m);
print_r($m);
Array
(
[0] => Array
(
[0] => src="/fofa/upload/2014-08/05/5.mp4"
[1] => src="..."
)
[1] => Array
(
[0] => "
[1] => "
)
[2] => Array
(
[0] => /fofa/upload/2014-08/05/5.mp4
[1] => ...
)
)
------解决方案--------------------
去看一下preg_match 的用法就明白了。
<<<txt 为PHP中的Heredoc 结构,它是表达字符串的一种方法。
可以看这里用法:http://php.net/manual/zh/language.types.string.php#language.types.string.syntax.heredoc