如何使用PHP获取字符串的一部分

亚历山大·塞巴尔第(Alexandre Thebaldi)

细绳:

$local = "/c/xampp/htdocs/path/storage/public/*"

如何在字符串上方爆炸并仅获得后面的部分/path

像这样

getPublicPart( $local ) // @return string "/storage/public/*"
用户557846

根据提供的信息,我可以做的最好的

<?php
$absolute = "/c/xampp/htdocs/path/storage/public/*";


function getPublicPart($path){
  $x=explode('path',$path);
return $x[1];
}

 echo  getPublicPart( $absolute ); // @return string "/storage/public/*"

演示:http : //codepad.viper-7.com/EXU7Q5

计划2

删除已知点之前的所有内容:

 function getPublicPart($path){
    return strstr($path, 'storage'); 
}
echo  getPublicPart( $absolute );

演示:http : //codepad.viper-7.com/YtAorb

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章