如何使用RegExp制作PHP BB代码? [英] How to make PHP BB Codes with RegExp?

查看:90
本文介绍了如何使用RegExp制作PHP BB代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的网站,我想要一个简单的BB代码系统.没什么特别的-只是超链接和图像暂时就可以了.

for my website, I want a simple BB code system. Nothing special--just hyperlinks and images will be fine for now.

我对RegExp不好.时期.但是,如果有人可以给我看一个例子,我也许可以抓住它,将其克隆到不同的标签中.

I'm not good with RegExp. Period. But if someone could show me an example, I may be able to grasp it to clone it into different tags.

非常感谢您的帮助!

推荐答案

用户要求一些简单的东西,所以我给了他一些简单的东西.

The user asked for something simple, so I gave him something simple.

$input = "[link=http://www.google.com]test[/link]";
$replacement = preg_replace('/\[link=(.*?)\](.*?)\[\/link\]/', '<a href="$1">$2</a>', $input);

其中/\[link=(.*?)\](.*?)\[\/link\]/是正则表达式,<a href="$1">$2</a>是格式,$input是输入/数据,而$replacement是返回值.

Where /\[link=(.*?)\](.*?)\[\/link\]/ is the regex, <a href="$1">$2</a> is the format, $input is the input/data, and $replacement is the return.

这篇关于如何使用RegExp制作PHP BB代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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