Why to use preg_replace it could be done as
echo str_replace($last,$replace,$fff);
Question
I'm trying to manipulate text by using the preg_replace()
function, the code is self explanatory:
$fff = "12345678910";
echo $fff . "<br>";
$last = substr($fff,-5);
echo $last . "<br><br>";
$replace = "...";
$final = preg_replace($last,$replace,$fff);
echo $final;
So if you don't understand I want to shorten $fff
by 5 characters and replace it with ...
then store the full word into $final
where I can use it later. But I get this error:
Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in C:\htdocs\test.php on line 11
Line 11:
$final = preg_replace($last,$replace,$fff);
Help is appreciated.
Solution
Why to use preg_replace it could be done as
echo str_replace($last,$replace,$fff);
OTHER TIPS
preg_replace uses regular expressions. You are probably looking for str_replace:
str_replace($last, $replace, $fff);