doubaomao9304 2010-09-16 13:46
浏览 6
已采纳

在PHP中将HTML重新处理为单行字符串的最佳方法是什么?

I'm working on a WordPress plugin that exports posts and associated data into a tab-seperated text format. It's almost finished, but I'm struggling to find the best method to re-process HTML into single strings.

I'm using a combination of preg_replace and htmlentities, but it's getting a little messy.

I'm sure there must be a preferred method for doing this, so I thought I would check with you? I can't find anything suitable on Google.

  • 写回答

2条回答 默认 最新

  • douyan3478 2010-09-16 14:05
    关注

    There's no single sure fire way but some simple regex would do the trick:

    // remove convert newlines and multiple spaces into 1 space
    $html = preg_replace("/\s+|
    +|/", ' ', $html);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题