简体   繁体   English

php格式html单行输出

[英]php format html output in a single line

So i have the next scenario using supersized slideshow in wordpress. 所以我有下一个在wordpress中使用超大幻灯片的场景。 on title i want to output html code, from wordpress posts. 关于标题,我想从wordpress帖子中输出html代码。 The code looks like this: 代码如下:

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

writing a post content in a single line, like this: 在一行中编写帖子内容,如下所示:

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

it will output: 它将输出:

{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 : ""}

what is ok and working. 好的,可以的。 But wordpress once u switch to Visual, adds indent to your code and it will look like this: 但是,一旦您切换到Visual,wordpress就会在您的代码中添加缩进,它看起来像这样:

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

and the output in this case will brake the slideshow: 在这种情况下,输出将制动幻灯片:

{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 : ""}

is there anyway i could tell php not to break the line there and output all the do_shortcode($content) in a single line 无论如何,我可以告诉php不要在那儿打断行并在一行中输出所有do_shortcode($content)

您可以执行以下操作:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM