php里如何截取某一段内容?

   更新日期:2024.05.02
function cut($file,$from,$end)
{
$posstart = stripos($file, $from);
if($posstart===FALSE)
{
return "can not find begin string!";
}
else
{
$posstart=$posstart+strlen($from);
}
$posend = strrpos($file, $end);
if($posstart===FALSE)
{
return "can not find end string!";
}
return substr($file, $posstart, $posend);
}

echo(cut("dddaaa3333aaas3aaa3ddddbbbdddaaa222bbb4bbbb3bbbvvv","aaa","bbb"));
试试看吧

  • 19656839071 :php从数组中取出一段?
    段钥鹏4801 :答:1.说明 array_slice ( array $array , int $offset [, int $length = null [, bool $preserve_keys = false ]] ) : array array_slice() 返回根据 offset 和 length 参数所指定的 array 数组中的一段序列。2....
  • 19656839071 :php截取某段英文
    段钥鹏4801 :答:基本思路是使用正则表达式匹配,程序先读取全文然后进行匹配,当匹配到你想要开始的“某字母”则开始截取,一直截取到最后就可以了。匹配函数可以用preg_match、preg_match_all,具体用法自己搜一下吧。
  • 19656839071 :php里如何截取某一段内容?
    段钥鹏4801 :答:function cut($file,$from,$end){ posstart = stripos($file, $from);if($posstart===FALSE){ return "can not find begin string!";} else { posstart=$posstart+strlen($from);} posend = strrpos($file, ...
  • 19656839071 :用php 写一段提取某个网页中的某段的代码
    段钥鹏4801 :答:php//获取网页内容$str=file_get_contents('http://book.zongheng.com/showchapter/199430.html');//删除 之前的内容if ($x=strpos($str,'')) $str=substr($str,$x);//删除 <!-- 章节列表 结束 -->之后的...
  • 19656839071 :php怎么截取字符后面几个字符?
    段钥鹏4801 :答:2:只要判断字符串1与字符串2之前的一个stripos位置然后再使用substr开始截取就可以了。3:PHP中的substr() 函数可以实现 substr() 函数返回字符串的一部分,substr(string,start,length)。4:string 必需,规定要返回其中...
  • 19656839071 :php里如何截取某一段内容?(再问)
    段钥鹏4801 :答:function open($file,$type=''){ if($open=file($file)){ count=count($open);for($i=0;$i<$count;$i++){ theget.=$open[$i];} }else{ die('请求过多,超时,请刷新');} return $theget;} _str =...
  • 19656839071 :php从数组中截取元素用哪个函数?
    段钥鹏4801 :答:用array_slice函数,下面引用自PHP手册:array array_slice ( array $array , int $offset [, int $length [, bool $preserve_keys ]] )array_slice() 返回根据 offset 和 length 参数所指定的 array 数组中的一段...
  • 19656839071 :PHP中如何截取从开头到某一位置的字符串?
    段钥鹏4801 :答:参数string为要操作的字符串,参数start为你要截取的字符串的开始位置,若start为负数时,则表示从倒数第start开始截取length个字符。PHP中的substr函数就可以做的到,只不过PHP把二个函数合二为一了。
  • 19656839071 :php有没有一种函数能从一个字符串中截取一段出来啊。
    段钥鹏4801 :答:正数 - 在字符串的指定位置开始 负数 - 在从字符串结尾的指定位置开始 0 - 在字符串中的第一个字符处开始 strstr() 函数搜索一个字符串在另一个字符串中的第一次出现 配合这几个函数就可以做到很强大的截取功能。
  • 19656839071 :PHP怎么获取里面的内容
    段钥鹏4801 :答:1、用file_get_contents,以get方式获取内容。2、用fopen打开url,以get方式获取内容。3、使用curl库,使用curl库之前,可能需要查看一下php.ini是否已经打开了curl扩展。4、用file_get_contents函数,以post方式获取url。
  • 相关链接

    欢迎反馈与建议,请联系电邮
    2024 © 视觉网