Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
停止php添加新行_Php_Javascript_Arrays_Wordpress_Newline - Fatal编程技术网

停止php添加新行

停止php添加新行,php,javascript,arrays,wordpress,newline,Php,Javascript,Arrays,Wordpress,Newline,我试图将我的wordpress博客中的帖子添加到javascript数组中,但是它不断添加新行并在javascript中导致错误。这是密码 <?php $num = 0 ; require($_SERVER['DOCUMENT_ROOT'] . '/blog/wp-load.php');query_posts('showposts=3');if (have_posts()) : while (have_posts()) : the_post(); ?> news_cont

我试图将我的wordpress博客中的帖子添加到javascript数组中,但是它不断添加新行并在javascript中导致错误。这是密码

  <?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(); ?>

新闻内容[]=“发布于”;
不断返回
post

和新行,导致错误


如何删除新行?

最简单的方法是修改函数
摘录

如果不可能:

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

如果是
\n
,您可以执行以下操作

str_replace("\n","",the_excerpt());
见: 请记住,它可能是
\n
\r\n
,具体取决于您的系统


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

如果不发布
exceprt()
我们几乎帮不了你。