2012-02-19 74 views
0

我想從我的文字新聞博客添加帖子到一個JavaScript數組,但它不斷添加一個新行,並在JavaScript中導致錯誤。這裏是代碼停止PHP添加新行

<?php $num = 0 ; require($_SERVER['DOCUMENT_ROOT'] . '/blog/wp-load.php');query_posts('showposts=3');if (have_posts()) : while (have_posts()) : the_post(); ?> 
    news_content[<?php echo $num; ?>]="<a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a>Posted on <?php the_time('l jS F, Y') ?><?php the_excerpt(); ?>"; 

    <?php $num = $num + 1; endwhile; else: echo "no posts"; endif; ?> 
    <?php wp_reset_query(); ?> 

the_excerpt();保持返回<p>post</p>和新的生產線,導致錯誤

我怎麼能擺脫新線?

+1

沒有發佈'the_exceprt()'我們幾乎不能幫你。 – Vyktor 2012-02-19 10:42:12

回答

1

最簡單的方法是修改函數the_excerpt

如果這是不可能的:

ob_start(); 
the_excerpt(); 
$out = ob_get_contents(); 
ob_end_clean(); 
echo rtrim($out); 
0

如果是\n,你可以做這樣的事情

str_replace("\n","",the_excerpt()); 

見:記住http://php.net/manual/en/function.str-replace.php 保持它可能是\n\r\n,根據在你的系統上。

我可以說「一行上的所有東西」php真的不可讀嗎?這很難維護,更不用說爲我們讀/調試了。爲什麼不多一些似是而非的佈局?