2012-03-20 130 views
0

所以我有下一個場景在wordpress中使用supersized slideshow。在標題上我想輸出HTML代碼,從WordPress的帖子。代碼如下所示:php格式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 : ""} 

什麼是確定和工作。但WordPress的一次u開關到視覺,增加縮進你的代碼,它看起來就像這樣:

<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)在單行

+4

你是手工生成的JSON。不要這樣做。使用'json_encode()':http://php.net/json-encode – 2012-03-20 16:39:05

+0

是的,使用json_encode()可以很好地解決問題。 非常感謝! – ciprian 2012-03-20 16:49:02

回答

0

你可以做這樣的事情:

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

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