【发布时间】:2011-03-17 16:34:20
【问题描述】:
在某个针出现后获取字符串部分的有效方法是什么,仅如果该针位于大海捞针的起点。类似于strstr(),但不包括针,并且仅在字符串开头找到时。
如果没有找到,最好返回 false。
我觉得我在这里忽略了一些非常明显的 PHP 函数,但我现在似乎想不起来。
例如:
$basePath = '/some/dir/';
$result = some_function( '/some/dir/this/is/the/relative/part', $basePath );
/*
should return:
this/is/the/relative/part
*/
$result = some_function( '/fake/dir/this/is/the/relative/part', $basePath );
$result = some_function( '/pre/some/dir/this/is/the/relative/part', $basePath );
/*
last example has '/some/dir/' in it, but not at start.
should both preferably return:
false
*/
我将把它用于应该充当沙盒的文件系统服务,并且应该能够提供和接收相对于基本沙盒目录的路径。
【问题讨论】: