I have a string like this:
S="str1|str2|str3"
I want extract another string from S which will contains only
t="str1|str2"
where | is the delimiter
thanks
$string = "str1|str2|str3";
$pieces = explode( '|', $string); // Explode on '|'
array_pop( $pieces); // Pop off the last element
$t = implode( '|', $pieces); // Join the string back together with '|'
Alternatively, use string manipulation:
$string = "str1|str2|str3";
echo substr( $string, 0, strrpos( $string, '|'));
I would take a look at the strpos function and at the substr function.
That is the way I would go about doing it.