0

I'am having trouble with a preg_replace() and I have tried to solve it for some time now. I'am getting this error:

preg_replace: Delimiter must not be alphanumeric or backslash

Here is my code:

$id = 23;
$titleForUrl = "I_like_cookies";
$uploadShortDesc = "This is the best desc and I love it 1242";

$uploadShortDesc = preg_replace('\1242\',
    '<a href="http:\/\/google.com\/freecookies\/'.$id.'-'.$titleForUrl.'">http:\/\/google.com\/freecookies\/'.$id.'-'.$titleForUrl.'.<\/a> ',
    $uploadShortDesc);
echo $uploadShortDesc;

Is should echo:

This is the best desc and I love it <a href="http://google.com/freecookies/23-  I_like_cookies">http://google.com/freecookies/23-I_like_cookies.</a>

I would love if someone could help me, I have put a \ in front of all / but I don't know why it won't work.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156

1 Answers1

0

Thanks Fred -ii- for the help!

it should look like:

$uploadShortDesc = preg_replace('\1242\', '<a href="http://google.com/freecookies/'.$id.'-'.$titleForUrl.'">http://google.com/freecookies/'.$id.'-'.$titleForUrl.'.</a> ', $uploadShortDesc);

Thanks! I really should read that manual more...

fortune
  • 3,361
  • 1
  • 20
  • 30
  • 1
    No problem. However, you've posted your own answers in other questions, where some solutions may have already been posted by someone else. Those are the ones that need to rewarded and accepted as the solution. That's how the Stack system rolls ;-) – Funk Forty Niner Jan 02 '15 at 03:24