字符串转 HTML?
我不明白为什么下面的代码将字符串返回为字符串而不是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]
转换为
。
有什么想法吗?
I can't understand why the code below return the string as a string but not as 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);
returns,
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
but it should return like this,
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.'Wallace &
Gromit's Children's Foundation
What I am trying to do is to convert [br]
to <br />
in the function.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试更改
为
替换使用
<
和>
的 HTML 代码而不是实际字符。Try changing
to
The replacement was using the HTML code for
<
and>
rather than the actual characters.您正在使用
<
和>
,它们是 HTML 实体,用于显示<
和> 。 html 页面上的
符号。您需要专门使用这些字符而不是实体,以便结果具有有效的 html 标签。You're using
<
and>
which are HTML entities use to display the<
and>
symbols on html pages. You need to use specifically these chars intead of the entities in order for the result to have valid html tags.