字符串:
$local = "/c/xampp/htdocs/path/storage/public/*"
如何在字符串上方爆炸并仅获取/path
之后的部分?
像这样的东西
getPublicPart( $local ) // @return string "/storage/public/*"
答案 0 :(得分:1)
根据提供的信息,我能做的最好
<?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/YtAorb
计划2
在已知点之前删除所有内容:
function getPublicPart($path){
return strstr($path, 'storage');
}
echo getPublicPart( $absolute );
演示:{{3}}
答案 1 :(得分:1)
strstr()
会这样做:
$absolute = "/c/xampp/htdocs/path/storage/public/*";
function getPublicPath($str,$needle = 'path/')
{
return str_replace($needle, '', strstr($str, $needle));
}
echo getPublicPath($absolute);
答案 2 :(得分:1)
您还可以使用一些非常基本的正则表达式来获取所需的信息:
<?php
$absolute = "/c/xampp/htdocs/path/storage/public/*";
function getPublicPath($str){
$pattern = "%path/(.*)%";
preg_match($pattern, $str, $match);
return $match[1];
}
echo getPublicPath($absolute);
?>