PHP Regex markdown from string

2019-01-20 13:56发布

问题:

I have this string: "Download it from [http://wordpress.org/extend/plugins/wordpress-mobile-admin/](http://wordpress.org/extend/plugins/wordpress-mobile-admin/)";

And i'm trying to convert this markdown to actual HTML, i tried getting the matches like so:

preg_match_all('/[(.*?)]((.*?))/', $data[$toProcess], $links);
debug($links);

Yet this..did not work.

Can anyone point me in the right direction to convert this markdown into HTML.

ps. i'd rather not import the whole markdown library.

回答1:

You need to escape the [, ], ( and ) as they are all regex meta-characters:

preg_match_all('/\[(.*?)\]\((.*?)\)/', $data[$toProcess], $links);