停止PHP添加新行

问题描述:

我想从我的文字新闻博客添加帖子到一个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

最简单的方法是修改函数the_excerpt

如果这是不可能的:

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

如果是\n,你可以做这样的事情

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

见:记住http://php.net/manual/en/function.str-replace.php 保持它可能是\n\r\n,根据在你的系统上。

我可以说“一行上的所有东西”php真的不可读吗?这很难维护,更不用说为我们读/调试了。为什么不多一些似是而非的布局?