替换"/"之前的任何字符串,PHP

X10*_*0nD 3 php

我想在"/"之前替换任何字符串,而不管字符串长度如何.

谢谢让

gho*_*g74 7

一种方式,假设你想在第一个"/"之前改变字符串.

$str = "anystring/the_rest/blah";
$s = explode("/",$str);
$s[0]="new string";
print_r ( implode("/",$s) );
Run Code Online (Sandbox Code Playgroud)