Hướng dẫn soundasleep/html2text - soundasleep/html2text

Hướng dẫn soundasleep/html2text - soundasleep/html2text

HTML2TEXT là một tập lệnh rất đơn giản sử dụng các phương thức DOM để chuyển đổi HTML thành định dạng tương tự như những gì sẽ được trình duyệt hiển thị - hoàn hảo cho những nơi bạn cần biểu diễn văn bản nhanh. Ví dụ:

Show

<html>
<title>Ignored Titletitle>
<body>
  <h2>Hello, World!h2>

  <p>This is some e-mail content.
  Even though it has whitespace and newlines, the e-mail converter
  will handle it correctly.

  <p>Even mismatched tags.p>

  <div>A divdiv>
  <div>Another divdiv>
  <div>A div<div>within a divdiv>div>

  <a href="http://foo.com">A linka>

body>
html>

Sẽ được chuyển đổi thành:

Hello, World!

This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly.

Even mismatched tags.

A div
Another div
A div
within a div

[A link](http://foo.com)

Xem bài đăng trên blog gốc hoặc câu trả lời Stackoverflow liên quan.

Cài đặt

Bạn có thể sử dụng trình soạn thảo để thêm gói vào dự án của mình:

{
  "require": {
    "soundasleep/html2text": "~1.1"
  }
}

Và sau đó sử dụng nó khá đơn giản:

$text = \Soundasleep\Html2Text::convert($html);

Bạn cũng có thể bao gồm html2text.php được cung cấp và sử dụng $text = convert_html_to_text($html); thay thế.

Tùy chọn

Quyền muaMặc địnhSự mô tả
ignore_errors falseĐặt thành
Hello, World!

This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly.

Even mismatched tags.

A div
Another div
A div
within a div

[A link](http://foo.com)
0 để bỏ qua bất kỳ lỗi phân tích cú pháp XML nào.
drop_links falseĐặt thành
Hello, World!

This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly.

Even mismatched tags.

A div
Another div
A div
within a div

[A link](http://foo.com)
0 để bỏ qua bất kỳ lỗi phân tích cú pháp XML nào.

Được đặt thành

Hello, World!

This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly.

Even mismatched tags.

A div
Another div
A div
within a div

[A link](http://foo.com)
0 thành không kết xuất các liên kết là
Hello, World!

This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly.

Even mismatched tags.

A div
Another div
A div
within a div

[A link](http://foo.com)
3, mà chỉ là
Hello, World!

This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly.

Even mismatched tags.

A div
Another div
A div
within a div

[A link](http://foo.com)
4.

$options = array(
  'ignore_errors' => true,
  // other options go here
);
$text = \Soundasleep\Html2Text::convert($html, $options);

Xét nghiệm

Xử lý sự cố

Lớp 'Domdocument' không tìm thấy

Giấy phép

Các phiên bản khác

Cũng xem HTML2TEXT_RUBY, một triển khai Ruby.

Bình luận

Brusch đã thêm một cam kết tham chiếu vấn đề này

Hướng dẫn soundasleep/html2text - soundasleep/html2text

…precated methods from Mail (#7644)

* Replace html2text/html2text with soundasleep/html2text and removed deprecated methods from Mail - fixes #7602

* Still allow to modify Html2Text options

* Update lib/Mail.php

Co-authored-by: Jacob Dreesen <>

* Feedback @jdreesen & @blankse

Co-authored-by: Jacob Dreesen <>

Ngày 2 tháng 12 năm 2020

Roland4432 đã thúc đẩy cam kết với Roland4432/Pimcore đã đề cập đến vấn đề này

…precated methods from Mail (pimcore#7644)

* Replace html2text/html2text with soundasleep/html2text and removed deprecated methods from Mail - fixes pimcore#7602

* Still allow to modify Html2Text options

* Update lib/Mail.php

Co-authored-by: Jacob Dreesen <>

* Feedback @jdreesen & @blankse

Co-authored-by: Jacob Dreesen <>