Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在第四个'/';_Php_String Split - Fatal编程技术网

Php 在第四个'/';

Php 在第四个'/';,php,string-split,Php,String Split,谁能帮帮我吗。我想在第四个“/”之后返回字符串中的所有内容 我尝试编辑的文件名为: /学生/levans10/public_html/cs130a/group4 所以我想包括cs130a/group4 我还想隔离levans10,以便在第2个和第3个“/”之间创建字符串 谢谢。这应该适合您: (只需用斜杠划出字符串,即可提取所需的部分,并再次打印) 之后,$parts[4]将成为cs130a/group4,$parts[2]是学生姓名 供参考: 你试过什么吗?是的,我试过。我目前有一个函数mak

谁能帮帮我吗。我想在第四个“/”之后返回字符串中的所有内容

我尝试编辑的文件名为:

/学生/levans10/public_html/cs130a/group4

所以我想包括cs130a/group4

我还想隔离levans10,以便在第2个和第3个“/”之间创建字符串


谢谢。

这应该适合您:

(只需用斜杠划出字符串,即可提取所需的部分,并再次打印)

之后,
$parts[4]
将成为
cs130a/group4
$parts[2]
是学生姓名

供参考:


你试过什么吗?是的,我试过。我目前有一个
函数makeURL(){$filelist=glob(getcwd().“/*”);$path=getcwd();$filename=substr(strrchr($path,“/”),1);如果($filelist!=false){print“这里有一些文件:

”;foreach($filelist作为$file){$url=”http://hills.ccsf.edu/~levans10/“$filename./”.substr($file,strrpos)($file,“/”)+1);print“$url

”;}}else{print“当前目录中没有文件!”;}}makeURL();
但是$filename只获取字符串的最后一部分,我需要更多。在分隔符上分解(
//code>)然后您可以单独访问任何部分。@John Doe这不是一个代码编写服务。Jonathan给了您一个很好的提示。@BigScar我知道这不是一个代码编写服务。谢谢!我一直在使用explode,但我缺少的是array_slice部分。现在我的函数将可移植到我的组成员:)。
<?php

    $str = "/students/levans10/public_html/cs130a/group4";
    $arr = explode("/", $str);
    echo implode("/", array_slice($arr, 4));//echo implode("/", array_slice($arr, 2, 1));

?>
cs130a/group4  //levans10
$input = '/students/levans10/public_html/cs130a/group4';
$parts = explode('/', $input, 5); // split string into max 5 parts
var_dump($parts);
array(5) {
  [0]=>
  string(0) ""
  [1]=>
  string(8) "students"
  [2]=>
  string(8) "levans10"
  [3]=>
  string(11) "public_html"
  [4]=>
  string(13) "cs130a/group4"
}