Which string function can I use to strip everything after - ? The string is not predefined so rtrim() does not work.
9453-abcafaf3ceb895d7b1636ad24c37cb9f-100.png?1
Use the splitexplode function and the "-" character as the delimiter. It will return an array of strings. If you only care about information before the first dash, just use the zeroth index of the returned array.
edit:
Sorry. After living in the python world for several months, split was the first thing that came to mind. explode is the correct function.
edit 2:
strip, lstrip, and rstrip are meant to be used for trimming whitespace off the end(s) of a string.
You could use substr and strpos:
$id = substr($path, 0, strpos($path, '-'));
Or alternatively preg_replace:
$id = preg_replace('/(.*?)-.*/', '\1', $path);
It depends on which dash? I would recommend using explode and just getting the array element for the string portion you want. Check it out: http://php.net/explode
Again, this will be very dependent on the amount of dashes in the string and may require additional logic.
If you want to exclude everything before the first hyphen and concatenate everything else, you could do this:
<?php
$str='9453-abcafaf3ceb895d7b1636ad24c37cb9f-100.png?1';
$str = explode('-', $str);
$count = count($str);
// So far we have the string exploded but we need to exclude
// the first element of the array and concatenate the others
$new = ''; // This variable will hold the concatenated string
for($i=1;$i<$count;++$i){
$new.=$str[$i];
}
echo $new; // abcafaf3ceb895d7b1636ad24c37cb9f100.png?1
?>
So, basically, you loop through the elements and concatenate them as they were initially, but now we are skipping the first one.