字符串的PHP Regex降价 [英] PHP Regex markdown from string

查看:70
本文介绍了字符串的PHP Regex降价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个字符串:"Download it from [http://wordpress.org/extend/plugins/wordpress-mobile-admin/](http://wordpress.org/extend/plugins/wordpress-mobile-admin/)";

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

我正在尝试将此降价转换为实际的HTML,我尝试像这样获取匹配项:

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);

但是这个..行不通.

任何人都可以向我指出正确的方向,以将这种降价转换为HTML.

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

ps.我不想导入整个markdown库.

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

推荐答案

您需要对[]()进行转义,因为它们都是正则表达式元字符:

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

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

这篇关于字符串的PHP Regex降价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆