【发布时间】:2012-02-03 00:03:42
【问题描述】:
我需要为我的网站执行以下操作。
$comment = "[item]Infinity Edge[/item]<br>[item]Eggnog Health Potion[/item]";
$this->site->bbcode->postBBCode($comment);
BBCode函数是这样的:
function postBBCode($string)
{
$string = nl2br($string);
$string = strip_tags($string, '<br></br>');
$string = $this->tagItem($string);
return $string;
}
function tagItem($string)
{
//Get all values between [item] and [/item] values
//Appoint them to an array.
//foreach item_name in array, call convertItems($item_name) function.
//Now, each item_name in array will be replaced with whatever convertItems($item_name) function returns.
//return modified string
}
function convertItems($itemName)
{
// -- I already made this function, but let me explain what it does.
//Query the database with $itemName.
//Get item_image from database.
//Return '<img src="$row['item_image']></img>';
}
好的,我已经在函数之间问了我的问题。我希望你明白我想要做什么。
基本上,[item] 和 [/item] 标记之间的任何内容都将转换为图像,但每个项目的图像路径将从数据库中获取。
我遇到困难的部分是正确获取 [item] 和 [/item] 标记之间的值。它应该得到它找到的所有正确匹配,而不是第一个匹配。
【问题讨论】:
标签: php function replace bbcode