0

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.

Jenz
  • 8,280
  • 7
  • 44
  • 77
user3332590
  • 101
  • 1
  • 1
  • 11
  • 1
    Please take a quick look at: http://stackoverflow.com/a/13025429/3387762 It should answer Your question. – Uriziel Mar 31 '14 at 12:09

2 Answers2

2

Why to use preg_replace it could be done as

echo str_replace($last,$replace,$fff);
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
1

preg_replace uses regular expressions. You are probably looking for str_replace:

str_replace($last, $replace, $fff);
nxu
  • 2,202
  • 1
  • 22
  • 34