当前位置:Gxlcms > PHP教程 > php截取特定段落如何操作

php截取特定段落如何操作

时间:2021-07-01 10:21:17 帮助过:4人阅读

比如用户通过文本框输入一串字符
第一次输入的内容:$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='推荐:';}else{$str='';}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='推荐:';}else{$str='';}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='推荐:';}else{$str='';}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='推荐:';}else{$str='';}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

谢谢你~~~~

人气教程排行