php--字符串截取方法-163

function str_rep($str_start,$str_end,$str)

 {


    $gethtml=$str;

    $end = stristr($gethtml,$str_end);//获取要截取区域的后面的内容

    $all = stristr($gethtml,$str_start);//截取从某个字符串开始到整个网页的结束处

    $title = str_replace($end,"",$all);//把要截取区域后面的内容替换为空

    $title = str_replace($str_start,"",$title);

    //$title = str_replace($str_start,"","$str");

    $title1 = str_replace($title,"",$str);

    $title1 = str_replace($str_start,"",$str);

    $title1 = str_replace($str_end,"",$title1);

    return $title1;

 }


$str = "2223333[attach]76[/attach]2q2[attach][/attach]";//整个内

//  2223333        76         2q2

echo str_rep("[attach]","[/attach]",$str);

//结果是:2223333762q2



//echo substr("12345678",0,strrpos("12345678",'7'));

//结果:123456



//截取某个字符之前的字符串(取最后一个=号之前的字符串)

echo $uri;

echo substr($uri ,0,strrpos($uri ,'='));

//结果如下:

http://localhost/itims/index.php?a=index&m=Isp&g=Om&menuid=359&order=numbering desc&order=numbering desc

http://localhost/itims/index.php?a=index&m=Isp&g=Om&menuid=359&order=numbering desc&order



//取后面的字符串

$a="/123/456/123/1.txt";

echo $a;

echo '<br/>============<br/>';

echo preg_replace('/^[\/]\w+\//','',$a);

//结果如下

/123/456/123/1.txt

============

456/123/1.txt


本文出自 “yanzi” 博客,谢绝转载!

你可能感兴趣的:(PHP)