停止 php 添加新行
我正在尝试将我的 Word Press 博客中的帖子添加到 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(); ?>
postthe_excerpt();
不断返回
和一个新行,导致错误
我怎样才能摆脱新行?
i am trying to add the posts from my word press blog to a javascript array however it keeps adding a new line and causing errors in the javascript. here is the code
<?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();
keeps returning <p>post</p>
and a new line, causing a error
How can i get rid of the new line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是修改函数
the_excerpt
。如果那不可能:
The simplest would be to modify the function
the_excerpt
.If that's not possible:
如果它是
\n
,您可以执行类似以下操作: http://php.net/manual/en/function.str-replace.php
请记住,它可能是
\n
或\r\n
,具体取决于您的系统。我可以说“所有内容都在一行”php 真的不可读吗?它真的很难维护,更不用说为我们阅读/调试了。为什么不采用一些更似是而非的布局?
If it is a
\n
, you can just do something likesee: http://php.net/manual/en/function.str-replace.php
Keeping in mind it might be
\n
or\r\n
, depending on your system.can I just remark that the "everything on one line" php is really unreadable? It's really hard to maintain, let alone to read/debug for us. Why not some more specious layout?