【问题标题】:How to concatenate post_title with post_content with html - wordpress如何将 post_title 与 post_content 与 html - wordpress 连接
【发布时间】:2017-06-19 21:33:51
【问题描述】:

我使用get_post(post_id) 来获取post_titlepost_content。我想将它们连接起来,post_title 将成为新字符串中的第一段。

例如。

$post_title = 'Hi all, welcome here'
$post_content = 'lorem ipsum bla bla la
new paragraph bla bla bla
new paragrapg lorem ipsum'

我希望得到这样的结果:

大家好,欢迎光临
lorem ipsum bla bla la
新段落bla bla bla
新的paragrapg lorem ipsum

但我不知道如何在post_title 之后传递新的段落字符。在 db view (mysql) 中没有标签,只有空格或隐藏字符。我正在尝试:

$new_string = $post_title.'/r/n'.$post_content
$new_string = '<p>'.$post_title.'</p>'.$post_content

但它不会起作用。

在此操作之后,我想使用apply_filters('the_content', $new_content) 来获得这个新字符串的正确视图,并使用 facebook SDK 将其发送到 facebook fanpage。

【问题讨论】:

  • \r\n,然后是nl2br();或&lt;br /&gt;
  • 有人需要阅读一些 PHP 基础知识:php.net/manual/en/…
  • 感谢您的回答和跟踪。这个对我有用:$new_string = $post_title.PHP_EOL.PHP_EOL.$post_content;
  • 无法编辑以前的答案@CBroe - 完全正确的双引号是正确答案。 &lt;br&gt; = "\n"&lt;p&gt; = "\n\n" 是正常行为?

标签: php html mysql wordpress facebook


【解决方案1】:

您应该使用 nl2br() 函数在段落中添加换行符。它会将所有 \n 转换为新行。

$new_string = nl2br($post_title.$post_content);

【讨论】:

  • 谢谢,但它对我不起作用。正确的答案是在"\n\n" 中使用 双引号 或使用 PHP_EOL 两次。
猜你喜欢
  • 1970-01-01
  • 2021-04-30
  • 2018-11-13
  • 1970-01-01
  • 1970-01-01
  • 2019-02-05
  • 1970-01-01
  • 2016-02-19
  • 1970-01-01
相关资源
最近更新 更多