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ụ:
Ignored Title
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 divwithin a div
A link
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][//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
ignore_errors | false | Đặt thành 0 để bỏ qua bất kỳ lỗi phân tích cú pháp XML nào. |
drop_links | false | Đặt thành 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][//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][//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][//foo.com]
4.$options = array[ 'ignore_errors' => true, // other options go here ]; $text = \Soundasleep\Html2Text::convert[$html, $options];
Truyền các tùy chọn cùng như một đối số thứ hai cho 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][//foo.com]
5, ví dụ:
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][//foo.com]
Xét nghiệm
Một số thử nghiệm rất cơ bản được cung cấp trong thư mục 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][//foo.com]
6. Chạy chúng với 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][//foo.com]
7.
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][//foo.com]
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][//foo.com]
Xử lý sự cố
Lớp 'Domdocument' không tìm thấy
Bạn cần cài đặt tiện ích mở rộng PHP XML cho phiên bản PHP của mình. ví dụ. 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][//foo.com]
8
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][//foo.com]
Giấy phép
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][//foo.com]
9 được cấp phép theo MIT, làm cho nó phù hợp cho cả các dự án Eclipse và GPL.
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][//foo.com]
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
…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