停止php添加新行
我试图将我的wordpress博客中的帖子添加到javascript数组中,但是它不断添加新行并在javascript中导致错误。这是密码停止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
<?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()
我们几乎帮不了你。