自制截取两个字符之间的字符串


也是为了抓取用下的。呵呵!估计到时候可以用了,要把这些整到一个文件下去。呵呵
<?php
function strcut($allStr,$star,$end){
 $starLen=strlen($star);
 $starInt="";
 $endInt="";
 $starInt=strpos($allStr,$star);
 if(empty($starInt)){
  return "error starInt";
  exit;
 }else{
  $starInt=$starInt+1+$starLen;
  $endInt=strpos($allStr,$end,$starInt);
  if(empty($endInt)){
   return "error endInt";
   exit;
 }
 else{
  $allLength=$endInt-$starInt;
  return substr($allStr,$starInt,$allLength);
  }
 }
}
?>


-------------------------------------------
正则表达式
function strcut($allStr,$star,$end){ //截取两个字符之间的字符串,返回字符串
 //if($allStr==""):return false;endif;
 eregi("".$star."(.*)".$end."", $allStr, $head);
 $head[0]=str_replace("".$star."","",$head[0]);
 $head[0]=str_replace("".$end."","",$head[0]);
 return $head[0];
}
posted @ 2009-08-27 10:36  火龙神  阅读(752)  评论(0编辑  收藏  举报