首页 > 后端开发 > php教程 > php截取特定段落如何操作

php截取特定段落如何操作

WBOY
发布: 2016-06-23 14:11:50
原创
1248 人浏览过

比如用户通过文本框输入一串字符
第一次输入的内容:$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\/([^\[\<\r\n]+?)\//i",//12"/http:\/\/www.boosj.com\/(.+?).html/i",//13"/http:\/\/www.bobmy.com\/FlvMovie\/VIEW(.+?).html/i",//14"/http:\/\/v.xgo.com.cn\/(.+?)\/(.+?).html/i",//15"/http:\/\/play.hupo.tv\/tv\/(.+?).html/",//16"/http:\/\/www.nnbbaa.com\/player.php\?id=(.+?)/",//16"/http:\/\/mv.2u.com.cn\/detail_(.+?).html/",//18"/http:\/\/vsearch.cctv.com\/plgs_play-(.+?).html/",//19 );	$ubb_replace = array("",//1	 );	$str_1 = preg_replace($ubb_search, $ubb_replace, $str);if($str !=$str_1){$str='<img  src=/templates/dian_1.gif alt="php截取特定段落如何操作" >推荐:';}else{$str='<img  src=/templates/dian.gif alt="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\/([^\[\<\r\n]+?)\//i",//12"/http:\/\/www.boosj.com\/(.+?).html/i",//13"/http:\/\/www.bobmy.com\/FlvMovie\/VIEW(.+?).html/i",//14"/http:\/\/v.xgo.com.cn\/(.+?)\/(.+?).html/i",//15"/http:\/\/play.hupo.tv\/tv\/(.+?).html/",//16"/http:\/\/www.nnbbaa.com\/player.php\?id=(.+?)/",//16"/http:\/\/mv.2u.com.cn\/detail_(.+?).html/",//18"/http:\/\/vsearch.cctv.com\/plgs_play-(.+?).html/",//19 );	$ubb_replace = array("",//1	 );	$str_1 = preg_replace($ubb_search, $ubb_replace, $str);if($str !=$str_1){$str='<img  src=/templates/dian_1.gif alt="php截取特定段落如何操作" >推荐:';}else{$str='<img  src=/templates/dian.gif alt="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\/([^\[\<\r\n]+?)\//i",//12"/http:\/\/www.boosj.com\/(.+?).html/i",//13"/http:\/\/www.bobmy.com\/FlvMovie\/VIEW(.+?).html/i",//14"/http:\/\/v.xgo.com.cn\/(.+?)\/(.+?).html/i",//15"/http:\/\/play.hupo.tv\/tv\/(.+?).html/",//16"/http:\/\/www.nnbbaa.com\/player.php\?id=(.+?)/",//16"/http:\/\/mv.2u.com.cn\/detail_(.+?).html/",//18"/http:\/\/vsearch.cctv.com\/plgs_play-(.+?).html/",//19 );	$ubb_replace = array("",//1	 );	$str_1 = preg_replace($ubb_search, $ubb_replace, $str);if($str !=$str_1){$str='<img  src=/templates/dian_1.gif alt="php截取特定段落如何操作" >推荐:';}else{$str='<img  src=/templates/dian.gif alt="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\/([^\[\<\r\n]+?)\//i",//12"/http:\/\/www.boosj.com\/(.+?).html/i",//13"/http:\/\/www.bobmy.com\/FlvMovie\/VIEW(.+?).html/i",//14"/http:\/\/v.xgo.com.cn\/(.+?)\/(.+?).html/i",//15"/http:\/\/play.hupo.tv\/tv\/(.+?).html/",//16"/http:\/\/www.nnbbaa.com\/player.php\?id=(.+?)/",//16"/http:\/\/mv.2u.com.cn\/detail_(.+?).html/",//18"/http:\/\/vsearch.cctv.com\/plgs_play-(.+?).html/",//19 );	$ubb_replace = array("",//1	 );	$str_1 = preg_replace($ubb_search, $ubb_replace, $str);if($str !=$str_1){$str='<img  src=/templates/dian_1.gif alt="php截取特定段落如何操作" >推荐:';}else{$str='<img  src=/templates/dian.gif alt="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 '<br>';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 '<br>';echo $m2[1];
登录后复制
登录后复制

25323843
XMzIzNjA2NjE2

谢谢你~~~~

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板