Heim >Backend-Entwicklung >PHP-Tutorial >php截取特定段落如何操作

php截取特定段落如何操作

WBOY
WBOYOriginal
2016-06-23 14:11:501245Durchsuche

比如用户通过文本框输入一串字符
第一次输入的内容:$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

谢谢你~~~~

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn