php格式的html输出在一行中


php format html output in a single line

所以我有了在wordpress中使用超大幻灯片的下一个场景。关于标题,我想输出html代码,来自wordpress的帖子。代码如下:

$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,wordpress就会在你的代码中添加缩进,它会看起来像这样:

<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)

您可以这样做:

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

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