php格式的html输出在一行中

时间:2012-03-20 16:36:59

标签: php wordpress format

所以我在wordpress中使用supersized slideshow的下一个场景。标题我想从wordpress帖子输出HTML代码。代码如下所示:

$output .= '{image : "'.$img_url.'", title : "'.do_shortcode($content).'", thumb : "'.$thumbnailsrc.'", url : ""},'."\n";

将帖子内容写在一行中,如下所示:

<h1>hei there</h1><span>how are you?</span>

它会输出:

{image : "http://localhost/mef/wp-content/uploads/2012/03/nature_0014.jpg", title : "<h1>hei there</h1><span>how are you?</span>", thumb : "http://localhost/mef/wp-content/uploads/2012/03/nature_0014-90x45.jpg", url : ""}

什么是好的和有效的。但是一旦你切换到Visual,你就会在你的代码中添加缩进,它将如下所示:

<h1>Hei there</h1>
<span>how are you?</span>

,这种情况下的输出会制作幻灯片:

{image : "http://localhost/mef/wp-content/uploads/2012/03/nature_0014.jpg", title : "<h1>hei there</h1>
<span>how are you?</span>", thumb : "http://localhost/mef/wp-content/uploads/2012/03/nature_0014-90x45.jpg", url : ""}

无论如何我可以告诉php不要在那里打破行并在一行中输出所有do_shortcode($content)

2 个答案:

答案 0 :(得分:0)

您可以这样做:

$noLineBreak = str_replace(array("\n", "\r\n", PHP_EOL), "", $input);

答案 1 :(得分:0)

你可以禁用wpautop()remove_filter('the_content', 'wpautop');