0

I have dynamic link build from variable :

/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....

morowind
  • 302
  • 1
  • 9
  • 24

2 Answers2

2

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.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
1

Maybe you can use strstr function?

$a = "before/after";
$b = strstr($a, "/",true); // gets text before /
$c = strstr($a, "/"); // gets text after /
Robik
  • 6,047
  • 4
  • 31
  • 41