【问题标题】:new line problems when parsing xml解析xml时的换行问题
【发布时间】:2017-07-02 20:06:39
【问题描述】:

我在我的网站中使用了 xml 上传选项,但问题是当我导入时,我跳过了所有新行并且单词只是粘在一起,我使用 php, 这是我如何将 xml 转换为数组:

$listings = Parser::xml($xml)['Listing'];

这是我保存文本的方式:

foreach ($listings as $item) {
    $listing->description = e(strip_tags ($item ['Web_Remarks']));
    $listing->save();
}

e() 是 laravel 函数,用于在保存到 DB 之前进行转义,strip_tags() - 此函数从 HTML、XML 和 PHP 标记中删除字符串

这里是输入 xml 示例:http://xml.propspace.com/feed/xml.php?cl=1107&pid=8245&acc=8807

这是最终结果,正如你所看到的那样,文本很糟糕:http://www.propertygiant.ae/listing/view/9908

所以我需要一种在我的文本中添加新行的方法,请帮助

【问题讨论】:

标签: php xml laravel laravel-5 laravel-4


【解决方案1】:

如果您通过以下方式保存:

$listing->description = e(strip_tags ($item ['Web_Remarks']));

使用nl2br() 换行。

$listing->description = e(nl2br(strip_tags ($item ['Web_Remarks'])));

【讨论】:

  • 谢谢,但它不起作用,因为它只是在文本末尾添加新行
  • 使用 nl2br 给了我新的一行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-01
  • 1970-01-01
相关资源
最近更新 更多