ok, now i done it,:
// x - haystack, y - needle, z - mode
function strcut($x,$y,$z) {
switch ($z) {
case '<-': return strstr($x,$y);
case '(-': return substr(strstr($x,$y),strlen($y),strlen($x));
case '->': return strrev(strstr(strrev($x),strrev($y)));
case '-)': return strrev(substr(strstr(strrev($x),strrev($y)),strlen($y),strlen($x)));
case '<' : return $y.strrev(substr(strrev($x),0,strpos($x,$y)));
case '(' : return strrev(substr(strrev($x),0,strpos($x,$y)));
case '>' : return substr($x,0,strpos($x,$y)).$y;
case ')' : return substr($x,0,strpos($x,$y));
default : echo "ERROR IN STRCUT"; break;};
};
//testing
$z = array('<-','(-','->','-)','<','(','>',')',);
$x = '123-XY-456-XY-789';
foreach ($z as $z) { echo $z.' = '.strcut($x,'XY',$z)."\n"; }
//output
//<- = XY-456-XY-789
//(- = -456-XY-789
//-> = 123-XY-456-XY
//-) = 123-XY-456-
//< = XY-789
//( = -789
//> = 123-XY
//) = 123-
the question is actually about particular expresiions, i want to avoit things like these:
strrev(substr(strstr(strrev($x),strrev($y)),strlen($y),strlen($x)))