1

I have the following code:

{bookielink href="bet-at-home"} body content{/bookielink}

and I want to get the following:

<a href="index.php?bookie=bet-at-home">body content</a>

This is my tries:

$buffer = preg_replace("/.*{bookielink[^>]*}|.*/si", "<a>", $buffer);
$buffer = preg_replace("/.*{\/bookielink}|.*/si", "</a>", $buffer);
ajreal
  • 46,720
  • 11
  • 89
  • 119
Kicsi Mano
  • 3,551
  • 3
  • 21
  • 26

1 Answers1

1

The following:

$buffer = 'foo {bookielink href="bet-at-home"} body content{/bookielink} bar';
echo preg_replace(
    '#{bookielink\s+href="([^"]*)"\s*}([^{]+){/bookielink}#i', 
    '<a href="index.php?bookie=$1">$2</a>', 
    $buffer
);

will print:

foo <a href="index.php?bookie=bet-at-home"> body content</a> bar
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
  • The regex seems fairly straightforward to me, but if you need some explanation, just say so, and I'll expand a bit. – Bart Kiers Sep 10 '11 at 11:08