天天看点

php 去掉字符串的最后一个字符 及 截取原字符串1,2,3,4,5,6, 

原字符串1,2,3,4,5,6, 

去掉最后一个字符",",最终结果为1,2,3,4,5,6 

代码如下:  $str = "1,2,3,4,5,6,";  $newstr = substr($str,0,strlen($str)-1);  echo $newstr;  echo 1,2,3,4,5,6

系统自带的函数即可实现这样的效果,两种方法:  substr($str, 0, -1)

//函数2

rtrim($str, ",")  #############截取 摘取 之间的字符串#########  

$str='> <span class="ib">test 23232</span></p> <h2 class="Colo';
preg_match_all('/class="ib">(.*?)</',$str,$ary);
print_r($ary);
           
function parseHeaders($requset){
   $resule =array();
   if (preg_match("/GET (.*) HTTP/",$requset,$match)) { $resule['reuqest'] = $match[1]; }
   if (preg_match("/Host: (.*)\r\n/",$requset,$match)) { $result['host'] = $match[1]; }
   if (preg_match("/Origin: (.*)\r\n/",$requset,$match)) { $result['origin'] = $match[1]; }
   if (preg_match("/Sec-WebSocket-Key: (.*)\r\n/",$requset,$match)) { $result['key'] = $match[1]; }
   return $result;
}
           
php