日期:2014-05-17  浏览次数:20513 次

php截取特定段落如何操作
比如用户通过文本框输入一串字符
第一次输入的内容:$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>推荐:';}
else{
$str='<img src=/templates/dian.gif>';
}
return $str;
}





供参考
------解决方案--------------------
$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