i am trying to use the preg_replace_callback but i am keep getting an error.
My goal is to if there is any (-) in the input, so it actually -1 value from the input.
For example ---
If the request value is "Iphone -5" it should be "Iphone 4"
public function justTestAction($string) {
$string = "Iphone -5";
$result = preg_replace_callback('/-d+/', 'callback', $string);
function callback($matches) {
return abs($matches[0]) - 1;
}
return $result;
}
My expected Output ---
Expected Output -Iphone 4
But i am keep getting this error ---
Warning: preg_replace_callback(): Requires argument 2, 'callback', to be a valid callback
Anyone knows how i can fix this issue !!!
See Question&Answers more detail:os