dounuogong0358 2017-05-23 07:51
浏览 16

如何将html页面转换为同一对齐的文本文件?

I have an HTML page which formats text as show below. I want to generate a text file with the same formatting.

 Text1                                                                 Text2 

    This is the paragraph1

    Text

    01.03.2017
    This is the paragraph 2

Currently, I am using the html2text class but the output I got is different,it shows this below output

    include("html2text/html2text.php");
    $text = convert_html_to_text($my_var);

Generates

Text1 Text2  This is paragraph 1 Text 01.03.2017 This is the paragraph2

So everything in in one line. But I want in the same format as when the HTML document render. How do I achieve this?

  • 写回答

2条回答 默认 最新

  • dongyoulou4829 2017-05-23 08:04
    关注

    Your HTML file does not contain HTML tags, so why would you want to convert it to text ? It is already a text file.

    You could add "pre" tags around the $my_var variable, perhaps the library that you use will preserve whitespace inside the tag.

    If that does not work you could first replace all double spaces with another string, do the conversion and then replace your string with double spaces again.

    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂