欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php截取特定段落如何操作

程序员文章站 2022-04-06 18:17:13
...
比如用户通过文本框输入一串字符
第一次输入的内容:$w1=" http://you.video.sina.com.cn/b/25323843-1272884840.html";
第二次输入的内容:$w2="http://v.youku.com/v_show/id_XMzIzNjA2NjE2.html";


第一次得到的结果:$val="25323843";
第二次得到的结果:$val="XMzIzNjA2NjE2";

假定上面两个值是用户自己分别输入的,请问程序怎样自动提取它们我所需要的值?能给个范例么?


求大家帮帮忙

回复讨论(解决方案)

//针对视频链接处理function url_1($str){$ubb_search = array("/http:\/\/(v|www).youku.com\/v_show\/id_(.+?).html/i",//1"/http:\/\/v.ku6.com\/show\/(.+?).html/i",//2"/http:\/\/www.tudou.com\/programs\/view\/(.+?)\//i",//3"/http:\/\/you.video.sina.com.cn\/b\/(.+?)-(.+?).html/i",//4"/http:\/\/(.+?).joy.cn\/video\/(.+?).htm/i",//5"/http:\/\/www.openv.com\/play\/(.+?).html/i",//6"/http:\/\/video.pomoho.com\/ent\/(.+?)/i",//7"/http:\/\/www.weplay.cn\/c2\/(.+?).html/i",//8"/http:\/\/v.blog.sohu.com\/u\/vw\/(.+?)/i",//9//"/http:\/\/vlog.17173.com\/v\/(.+?)\/(.+?)\/(.+?)\/(.+?)/i",//10"/http:\/\/www.letv.com\/ptv\/vplay\/(.+?)/i",//11"/http:\/\/tv.mofile.com\/([^\[\推荐:';}else{$str='php截取特定段落如何操作';}return $str;}



供参考

//针对视频链接处理function url_1($str){$ubb_search = array("/http:\/\/(v|www).youku.com\/v_show\/id_(.+?).html/i",//1"/http:\/\/v.ku6.com\/show\/(.+?).html/i",//2"/http:\/\/www.tudou.com\/programs\/view\/(.+?)\//i",//3"/http:\/\/you.video.sina.com.cn\/b\/(.+?)-(.+?).html/i",//4"/http:\/\/(.+?).joy.cn\/video\/(.+?).htm/i",//5"/http:\/\/www.openv.com\/play\/(.+?).html/i",//6"/http:\/\/video.pomoho.com\/ent\/(.+?)/i",//7"/http:\/\/www.weplay.cn\/c2\/(.+?).html/i",//8"/http:\/\/v.blog.sohu.com\/u\/vw\/(.+?)/i",//9//"/http:\/\/vlog.17173.com\/v\/(.+?)\/(.+?)\/(.+?)\/(.+?)/i",//10"/http:\/\/www.letv.com\/ptv\/vplay\/(.+?)/i",//11"/http:\/\/tv.mofile.com\/([^\[\推荐:';}else{$str='php截取特定段落如何操作';}return $str;}



供参考

这个应该是从discuz里面拿出来的吧?

//针对视频链接处理function url_1($str){$ubb_search = array("/http:\/\/(v|www).youku.com\/v_show\/id_(.+?).html/i",//1"/http:\/\/v.ku6.com\/show\/(.+?).html/i",//2"/http:\/\/www.tudou.com\/programs\/view\/(.+?)\//i",//3"/http:\/\/you.video.sina.com.cn\/b\/(.+?)-(.+?).html/i",//4"/http:\/\/(.+?).joy.cn\/video\/(.+?).htm/i",//5"/http:\/\/www.openv.com\/play\/(.+?).html/i",//6"/http:\/\/video.pomoho.com\/ent\/(.+?)/i",//7"/http:\/\/www.weplay.cn\/c2\/(.+?).html/i",//8"/http:\/\/v.blog.sohu.com\/u\/vw\/(.+?)/i",//9//"/http:\/\/vlog.17173.com\/v\/(.+?)\/(.+?)\/(.+?)\/(.+?)/i",//10"/http:\/\/www.letv.com\/ptv\/vplay\/(.+?)/i",//11"/http:\/\/tv.mofile.com\/([^\[\推荐:';}else{$str='php截取特定段落如何操作';}return $str;}



供参考

这个应该是从discuz里面拿出来的吧?

//针对视频链接处理function url_1($str){$ubb_search = array("/http:\/\/(v|www).youku.com\/v_show\/id_(.+?).html/i",//1"/http:\/\/v.ku6.com\/show\/(.+?).html/i",//2"/http:\/\/www.tudou.com\/programs\/view\/(.+?)\//i",//3"/http:\/\/you.video.sina.com.cn\/b\/(.+?)-(.+?).html/i",//4"/http:\/\/(.+?).joy.cn\/video\/(.+?).htm/i",//5"/http:\/\/www.openv.com\/play\/(.+?).html/i",//6"/http:\/\/video.pomoho.com\/ent\/(.+?)/i",//7"/http:\/\/www.weplay.cn\/c2\/(.+?).html/i",//8"/http:\/\/v.blog.sohu.com\/u\/vw\/(.+?)/i",//9//"/http:\/\/vlog.17173.com\/v\/(.+?)\/(.+?)\/(.+?)\/(.+?)/i",//10"/http:\/\/www.letv.com\/ptv\/vplay\/(.+?)/i",//11"/http:\/\/tv.mofile.com\/([^\[\推荐:';}else{$str='php截取特定段落如何操作';}return $str;}



供参考

这个应该是从discuz里面拿出来的吧?

$w1=" http://you.video.sina.com.cn/b/25323843-1272884840.html";$w2="http://v.youku.com/v_show/id_XMzIzNjA2NjE2.html";preg_match('/\/(\d+)-/',$w1,$m1);preg_match('/id_(.+?)\./',$w2,$m2);echo $m1[1];echo '
';echo $m2[1];

25323843
XMzIzNjA2NjE2

$w1=" http://you.video.sina.com.cn/b/25323843-1272884840.html";$w2="http://v.youku.com/v_show/id_XMzIzNjA2NjE2.html";preg_match('/\/(\d+)-/',$w1,$m1);preg_match('/id_(.+?)\./',$w2,$m2);echo $m1[1];echo '
';echo $m2[1];

25323843
XMzIzNjA2NjE2

谢谢你~~~~