php正则截取字符串 正则 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $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] => ... )) 成功了十分感谢,还想请教个问题,就是为什么$m数组里面会用两遍匹配的内容,还有就是字符串前的“<<<txt”有啥用 去看一下preg_match 的用法就明白了。<<<txt 为PHP中的Heredoc 结构,它是表达字符串的一种方法。可以看这里用法:http://php.net/manual/zh/language.types.string.php#language.types.string.syntax.heredoc 帮我改一下这个php.显示ip的问题: discuz实时查询数据问题 求解一段代码的含义,大概即可 apache 运行100%的问题,求求各位老前辈, php会缓存include的文件吗? php异常处理机制怎么解决 如何用PHP为图片批量加水印 给点思路!谢谢! 哪位发一个windows操作系统专区的地址? 请问fileperms这个函数返回的值是什么 php socket服务端能不能在网页端开启?而不是只能用CLI模式开启 php 页面跳转 本地windows 环境正常,上传linux 服务器上跳转不了
<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];
字符串的格式是<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] => ...
))
可以看这里用法:http://php.net/manual/zh/language.types.string.php#language.types.string.syntax.heredoc