【问题标题】:Drupal 6 programmatically adding \r\n showingDrupal 6 以编程方式添加 \r\n 显示
【发布时间】:2012-05-01 04:00:59
【问题描述】:

我有一个 PHP 脚本,可以将故事节点添加到我的 drupal 网站:

function post_to_webpage($title, $body, $teaser, $promote) {
//set the working directory to your Drupal root
chdir($_SERVER["DOCUMENT_ROOT"].'/webpage/');

//require the bootstrap include
require_once './includes/bootstrap.inc';

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 
//(loads everything, but doesn't render anything)
$node = new stdClass();
$node->type = 'story';
$node->title = $title;
$node->body = $body;
$node->teaser = $teaser;
$node->uid = 1;
$node->status = 1;
$node->promote = $promote;
$node->format = 2;
$node->sticky = 1;

node_save($node);

return $node->nid; }

但是我经常在这些节点的内容中看到 r\n\。什么可能导致这种情况?

编辑:示例输出:

Lorem ipsum dolor sit amet,consectetur adipiscing elit。 Sed 前庭 ultrices ultricies。 Curabitur nibh risus、mattis rhoncus dignissim vel、laoreet sit amet neque。 Praesent blandit arcu et nisl ornare semper。
\r\n
\r\n
Vestibulum eleifend malesuada odio,aliquet mauris sagittis sed。 Proin 坐在 sed urna 中的 amet libero quis nibh malesuada mattis。 Nullam rutrum egestas interdum。 sed dui lorem, faucibus et sagittis in, volutpat at velit。

【问题讨论】:

  • 您说的很模糊,请展示您的输出示例,包括有问题的中断。
  • 在保存节点主体或将其打印到屏幕之前,您需要查看nl2br() function

标签: php drupal drupal-6 drupal-nodes


【解决方案1】:

真正有用的是,如果您可以发布您提交的文本,从而产生上述输出。但是,根据所说的,这听起来很可能是由输入格式过滤器或缺少特定过滤器引起的。可能的原因是 换行符 过滤器未启用。要检查您的过滤器,请访问:

/admin/settings/filters/list

默认是过滤的 HTML。因为您正在以编程方式添加内容,所以这很可能是应用于您提交的过滤器。单击此条目右侧的配置。向下滚动页面,查找名为“换行转换器”的过滤器。如果尚未启用,请单击它并保存配置。然后尝试以相同的方式创建一些新内容。

您可以在http://www.lullabot.com/blog/articles/drupal-input-formats-and-filters 找到有关输入过滤器的更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-20
    • 1970-01-01
    • 2013-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多