PHP 正则表达式从字符串降价

发布于 2024-12-18 11:48:49 字数 408 浏览 3 评论 0原文

我有这个字符串:“从[http://wordpress.org/extend/plugins/wordpress-mobile-admin/](http://wordpress.org/extend/plugins/wordpress-mobile-admin)下载它/)";

我正在尝试将这个 markdown 转换为实际的 HTML,我尝试像这样获取匹配:

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

但这.. 不起作用。

任何人都可以指出我将这个 Markdown 转换为 HTML 的正确方向吗?

附:我不想导入整个 Markdown 库。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

箹锭⒈辈孓 2024-12-25 11:48:49

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

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

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

preg_match_all('/\[(.*?)\]\((.*?)\)/', $data[$toProcess], $links);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文