0

I am not at all experienced with regex, so please bear with me.

I am building a simple content markup language for an admin.

I want for the admin user to be able to create a link by specifying the following within an admin;

[link="http://www.google.com"]Google[/link]

From this, I need to basically get the value XXX in [link="XXX"] and the value between [link="abcd"]XXX[/link]. So for the above example I'd want to extract 'http://www.google.com' and 'Google'.

I am working with PHP.

Any help would be greatly appreciated.

BenPRJ
  • 39
  • 5

1 Answers1

0

you can use preg_match like this

$url = '[link="http://www.google.com"]Google[/link]';   
preg_match('/\[link=\"(.+?)\"\](.+?)\[\/link\]/', $url, $matches);
print_r($matches);

$matches will contain

Array
(
    [0] => [link="http://www.google.com"]Google[/link]
    [1] => http://www.google.com
    [2] => Google
)
roullie
  • 2,830
  • 16
  • 26