我不明白为什么下面的代码将字符串作为字符串返回,而不是以html的形式返回,
function en_code($string)
{
# find the match of [br] = a break = <br>
$output = preg_replace('/\[(?: |\s)*([br]+)(?: |\s)*\]/', '<$1 />', $string);
# return the result
return $output;
}
$string = 'Wallace and Gromit\'s Children Foundation the whole campaign was exemplary, showing true professionalism, creativity and an amazing understanding of what makes a strong news story.\'[br][br]Wallace & Gromit\'s Children\'s Foundation';
echo en_code($string);返回,
Wallace and Gromit's Children Foundation the whole campaign was
exemplary, showing true professionalism, creativity and an amazing
understanding of what makes a strong news story.'<br /><br />Wallace &
Gromit's Children's Foundation但它应该像这样回来,
华莱士和格罗米特儿童基金会整个运动堪称楷模,展现了真正的专业精神、创造力和惊人的理解,使一个强大的新闻故事。
我要做的是在函数中将[br]转换为<br />。
有什么想法吗?
发布于 2011-10-13 14:01:29
试着改变
$output = preg_replace('/\[(?: |\s)*([br]+)(?: |\s)*\]/', '<$1 />', $string);至
$output = preg_replace('/\[(?: |\s)*([br]+)(?: |\s)*\]/', '<$1 />', $string);替代方法是使用<和>的HTML代码,而不是实际的字符。
发布于 2011-10-13 14:02:48
您使用的是<和>,它们是HTML实体用来在html页面上显示<和>符号的。为了使结果具有有效的html标记,您需要具体地使用这些实体的字符整数。
https://stackoverflow.com/questions/7755226
复制相似问题