故梦吖

php截取特定字符前面后面中间的内容

<?php
$text = "123456789";
//保存一段文字
echo substr($text,strripos($text,"5")+1);
//输出5之后内容
echo substr($text,0,strrpos($text,"5"));
//输出5之前内容
echo substr(substr($text,0,strrpos($text,"8")),strripos(substr($text,0,strrpos($text,"8")),"5")+1);
//输出5之后8之前的内容
?>


<?php
preg_match('/.*?<p>(\d*?)<\/p>.*?/', "<p>www.gmit.vip</p>", $res);
echo $res;
//输出 www.gmit.vip
?>

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »