Remove text after certain word
I have dynamic link build from v开发者_如何学运维ariable :
/Tinkle/Matte/BlackHyper/Black/Gunmetal
How can I remove all text after variable value "BlackHyper" to become: "/Tinkle/Matte/BlackHyper"
I try rtrim :
$param="BlackHyper";
$str="/Tinkle/Matte/BlackHyper/Black/Gunmetal"; rtrim($str,$param);
No luck , remove some letters....
RTrim doesnt work like this.
You need to do something like this
$pos = strpos($str, $param);
$endpoint = $pos + strlen($param);
$newStr = substr($str,0,$endpoint );
This will create a new string (there might be a bug or two I havent tested it) with all characters up to your param.
Maybe you can use strstr function?
$a = "before/after";
$b = strstr($a, "/",true); // gets text before /
$c = strstr($a, "/"); // gets text after /
精彩评论