Hướng dẫn convert html to text php - chuyển đổi html sang văn bản php
Ngày đăng:10/11/2022
Trả lời:0
Lượt xem:101
Tôi sử dụng tinymce để cho phép định dạng văn bản tối thiểu trong trang web của mình. Từ HTML được sản xuất, tôi muốn chuyển đổi nó thành văn bản đơn giản cho e-mail. Tôi đã sử dụng một lớp có tên HTML2TEXT, nhưng nó thực sự thiếu hỗ trợ UTF-8, trong số những thứ khác. Tuy nhiên, tôi làm như vậy, nó ánh xạ một số thẻ HTML thành định dạng văn bản đơn giản - như đặt dấu gạch dưới xung quanh văn bản mà trước đây có thẻ trong HTML.
Có ai sử dụng một cách tiếp cận tương tự để chuyển đổi HTML thành văn bản đơn giản trong PHP không? Và nếu vậy: Bạn có đề xuất bất kỳ lớp bên thứ ba nào tôi có thể sử dụng không? Hoặc làm thế nào để bạn giải quyết tốt nhất vấn đề này?
Benmorel
32.9K48 Huy hiệu vàng173 Huy hiệu bạc 306 Huy hiệu đồng48 gold badges173 silver badges306 bronze badges
Hỏi ngày 10 tháng 12 năm 2009 lúc 22:31Dec 10, 2009 at 22:31
Justin Staytonjustin StaytonJustin Stayton
5.7918 Huy hiệu vàng36 Huy hiệu bạc43 Huy hiệu đồng8 gold badges36 silver badges43 bronze badges
8
Sử dụng HTML2TEXT (ví dụ HTML vào văn bản), được cấp phép theo giấy phép công cộng Eclipse. Nó sử dụng các phương thức DOM của PHP để tải từ HTML và sau đó lặp lại DOM kết quả để trích xuất văn bản thuần túy. Cách sử dụng:
// when installed using the Composer package
$text = Html2Text\Html2Text::convert($html);
// usage when installed using html2text.php
require('html2text.php');
$text = convert_html_to_text($html);
Mặc dù không đầy đủ, nó là nguồn mở và đóng góp được hoan nghênh.
Các vấn đề với các tập lệnh chuyển đổi khác:
Vì html2text (GPL) không tương thích với EPL.
Liên kết của Lkessler (Attribution) không tương thích với hầu hết các giấy phép nguồn mở.
Abhi Beckert
32.1K12 Huy hiệu vàng82 Huy hiệu bạc110 Huy hiệu đồng12 gold badges82 silver badges110 bronze badges
Đã trả lời ngày 2 tháng 4 năm 2010 lúc 0:32Apr 2, 2010 at 0:32
8
Có chức năng dải_tags đáng tin cậy. Nó không đẹp mặc dù. Nó sẽ chỉ vệ sinh. Bạn có thể kết hợp nó với một chuỗi thay thế để có được sự nhấn mạnh của bạn.
Về UTF-8, việc viết trên trang "Howto" trạng thái:
Hỗ trợ riêng của PHP cho Unicode khá kém và không phải lúc nào cũng xử lý UTF-8 một cách chính xác. Mặc dù tập lệnh HTML2TEXT sử dụng các phương thức an toàn Unicode-step (mà không cần mô-đun MBString), nhưng nó không thể luôn luôn đối phó với việc xử lý mã hóa của PHP. PHP không thực sự hiểu unicode hoặc mã hóa như UTF-8 và sử dụng mã hóa cơ sở của hệ thống, có xu hướng là một trong những gia đình ISO-8859. Kết quả là, những gì có thể nhìn vào bạn giống như một ký tự hợp lệ trong trình soạn thảo văn bản của bạn, trong UTF-8 hoặc một byte đơn, cũng có thể bị Php giải thích sai. Vì vậy, mặc dù bạn nghĩ rằng bạn đang nuôi một ký tự hợp lệ vào HTML2Text, bạn cũng có thể không.
Tác giả cung cấp một số cách tiếp cận để giải quyết vấn đề này và nói rằng phiên bản 2 của HTML2TEXT (sử dụng DomDocument) có hỗ trợ UTF-8.
Lưu ý các hạn chế cho sử dụng thương mại.
Dave Jarvis
29.6K38 Huy hiệu vàng176 Huy hiệu bạc 307 Huy hiệu đồng38 gold
badges176 silver badges307 bronze badges
Đã trả lời ngày 17 tháng 3 năm 2010 lúc 21:52Mar 17, 2010 at 21:52
lkesslerlkesslerlkessler
Huy hiệu vàng 19.8K3434 gold badges133 silver badges201 bronze badges
1
Bạn có thể sử dụng Lynx với các tùy chọn -stdin và -dump để đạt được điều đó:
array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/htmp2txt.log", "a") // stderr is a file to write to
);
$process = proc_open('lynx -stdin -dump 2>&1', $descriptorspec, $pipes, '/tmp', NULL);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to htmp2txt.log
$stdin = $pipes[0];
fwrite($stdin, <<<'EOT'
TEST
Lorem Ipsum
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et sapien ut erat porttitor suscipit id nec dui. Nam rhoncus mauris ac dui tristique bibendum. Aliquam molestie placerat gravida. Duis vitae tortor gravida libero semper cursus eu ut tortor. Nunc id orci orci. Suspendisse potenti. Phasellus vehicula leo sed erat rutrum sed blandit purus convallis.
Aliquam feugiat, neque a tempus rhoncus, neque dolor vulputate eros, non pellentesque elit lacus ut nunc. Pellentesque vel purus libero, ultrices condimentum lorem. Nam dictum faucibus mollis. Praesent adipiscing nunc sed dui ultricies molestie. Quisque facilisis purus quis felis molestie ut accumsan felis ultricies. Curabitur euismod est id est pretium accumsan. Praesent a mi in dolor feugiat vehicula quis at elit. Mauris lacus mauris, laoreet non molestie nec, adipiscing a nulla. Nullam rutrum, libero id pellentesque tempus, erat nibh ornare dolor, id accumsan est risus at leo. In convallis felis at eros condimentum adipiscing aliquam nisi faucibus. Integer arcu ligula, porttitor in fermentum vitae, lacinia nec dui.
EOT
);
fclose($stdin);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
Đã trả lời ngày 8 tháng 3 năm 2012 lúc 2:32Mar 8, 2012 at 2:32
nad2000nad2000nad2000
4.1781 Huy hiệu vàng27 Huy hiệu bạc23 Huy hiệu đồng1 gold badge27 silver badges23 bronze badges
Đã trả lời ngày 11 tháng 8 năm 2017 lúc 8:11Aug 11, 2017 at 8:11
Aommy Indyaommy IndyAommy Indy
Huy hiệu đồng 1191 Bạc5 Huy hiệu Đồng1 silver badge5 bronze badges
1
Nếu bạn muốn chuyển đổi các ký tự đặc biệt HTML và không chỉ loại bỏ chúng cũng như loại bỏ mọi thứ và chuẩn bị cho văn bản đơn giản thì đây là giải pháp hoạt động cho tôi ...
Đã trả lời ngày 15 tháng 5 năm 2018 lúc 14:36May 15, 2018 at 14:36
JayjayJay
4263 Huy hiệu bạc17 Huy hiệu đồng3 silver badges17 bronze badges
Markdownify chuyển đổi HTML thành Markdown, một hệ thống định dạng văn bản đơn giản được sử dụng trên chính trang web này.
Đã trả lời ngày 28 tháng 12 năm 2011 lúc 10:14Dec 28, 2011 at 10:14
Outisoutisoutis
73,8K20 Huy hiệu vàng147 Huy hiệu bạc218 Huy hiệu đồng20 gold badges147 silver badges218 bronze badges
1
Tôi đã gặp phải vấn đề tương tự như OP và thử một số giải pháp từ các câu trả lời hàng đầu ở trên không chứng minh được hoạt động cho các kịch bản của tôi. Xem tại sao cuối cùng.
Thay vào đó, tôi thấy tập lệnh hữu ích này, để tránh nhầm lẫn, hãy gọi nó là
Đây thực sự là một phiên bản cập nhật của một tập lệnh đã được đề cập -
array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/htmp2txt.log", "a") // stderr is a file to write to
);
$process = proc_open('lynx -stdin -dump 2>&1', $descriptorspec, $pipes, '/tmp', NULL);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to htmp2txt.log
$stdin = $pipes[0];
fwrite($stdin, <<<'EOT'
TEST
Lorem Ipsum
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et sapien ut erat porttitor suscipit id nec dui. Nam rhoncus mauris ac dui tristique bibendum. Aliquam molestie placerat gravida. Duis vitae tortor gravida libero semper cursus eu ut tortor. Nunc id orci orci. Suspendisse potenti. Phasellus vehicula leo sed erat rutrum sed blandit purus convallis.
Aliquam feugiat, neque a tempus rhoncus, neque dolor vulputate eros, non pellentesque elit lacus ut nunc. Pellentesque vel purus libero, ultrices condimentum lorem. Nam dictum faucibus mollis. Praesent adipiscing nunc sed dui ultricies molestie. Quisque facilisis purus quis felis molestie ut accumsan felis ultricies. Curabitur euismod est id est pretium accumsan. Praesent a mi in dolor feugiat vehicula quis at elit. Mauris lacus mauris, laoreet non molestie nec, adipiscing a nulla. Nullam rutrum, libero id pellentesque tempus, erat nibh ornare dolor, id accumsan est risus at leo. In convallis felis at eros condimentum adipiscing aliquam nisi faucibus. Integer arcu ligula, porttitor in fermentum vitae, lacinia nec dui.
EOT
);
fclose($stdin);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
0 - được cập nhật bởi RoundCube Mail.
Usage:
$h2t = new \Html2Text\Html2Text('Hello, "world"');
echo $h2t->getText(); // prints Hello, "WORLD"
array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/htmp2txt.log", "a") // stderr is a file to write to
);
$process = proc_open('lynx -stdin -dump 2>&1', $descriptorspec, $pipes, '/tmp', NULL);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to htmp2txt.log
$stdin = $pipes[0];
fwrite($stdin, <<<'EOT'
TEST
Lorem Ipsum
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et sapien ut erat porttitor suscipit id nec dui. Nam rhoncus mauris ac dui tristique bibendum. Aliquam molestie placerat gravida. Duis vitae tortor gravida libero semper cursus eu ut tortor. Nunc id orci orci. Suspendisse potenti. Phasellus vehicula leo sed erat rutrum sed blandit purus convallis.
Aliquam feugiat, neque a tempus rhoncus, neque dolor vulputate eros, non pellentesque elit lacus ut nunc. Pellentesque vel purus libero, ultrices condimentum lorem. Nam dictum faucibus mollis. Praesent adipiscing nunc sed dui ultricies molestie. Quisque facilisis purus quis felis molestie ut accumsan felis ultricies. Curabitur euismod est id est pretium accumsan. Praesent a mi in dolor feugiat vehicula quis at elit. Mauris lacus mauris, laoreet non molestie nec, adipiscing a nulla. Nullam rutrum, libero id pellentesque tempus, erat nibh ornare dolor, id accumsan est risus at leo. In convallis felis at eros condimentum adipiscing aliquam nisi faucibus. Integer arcu ligula, porttitor in fermentum vitae, lacinia nec dui.
EOT
);
fclose($stdin);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
0 không hoạt động ngoài hộp cho các trường hợp có mã/tên HTML đặc biệt (ví dụ:
array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/htmp2txt.log", "a") // stderr is a file to write to
);
$process = proc_open('lynx -stdin -dump 2>&1', $descriptorspec, $pipes, '/tmp', NULL);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to htmp2txt.log
$stdin = $pipes[0];
fwrite($stdin, <<<'EOT'
TEST
Lorem Ipsum
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et sapien ut erat porttitor suscipit id nec dui. Nam rhoncus mauris ac dui tristique bibendum. Aliquam molestie placerat gravida. Duis vitae tortor gravida libero semper cursus eu ut tortor. Nunc id orci orci. Suspendisse potenti. Phasellus vehicula leo sed erat rutrum sed blandit purus convallis.
Aliquam feugiat, neque a tempus rhoncus, neque dolor vulputate eros, non pellentesque elit lacus ut nunc. Pellentesque vel purus libero, ultrices condimentum lorem. Nam dictum faucibus mollis. Praesent adipiscing nunc sed dui ultricies molestie. Quisque facilisis purus quis felis molestie ut accumsan felis ultricies. Curabitur euismod est id est pretium accumsan. Praesent a mi in dolor feugiat vehicula quis at elit. Mauris lacus mauris, laoreet non molestie nec, adipiscing a nulla. Nullam rutrum, libero id pellentesque tempus, erat nibh ornare dolor, id accumsan est risus at leo. In convallis felis at eros condimentum adipiscing aliquam nisi faucibus. Integer arcu ligula, porttitor in fermentum vitae, lacinia nec dui.
EOT
);
fclose($stdin);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
3) hoặc trích dẫn không ghép đôi (ví dụ:
array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/htmp2txt.log", "a") // stderr is a file to write to
);
$process = proc_open('lynx -stdin -dump 2>&1', $descriptorspec, $pipes, '/tmp', NULL);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to htmp2txt.log
$stdin = $pipes[0];
fwrite($stdin, <<<'EOT'
TEST
Lorem Ipsum
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et sapien ut erat porttitor suscipit id nec dui. Nam rhoncus mauris ac dui tristique bibendum. Aliquam molestie placerat gravida. Duis vitae tortor gravida libero semper cursus eu ut tortor. Nunc id orci orci. Suspendisse potenti. Phasellus vehicula leo sed erat rutrum sed blandit purus convallis.
Aliquam feugiat, neque a tempus rhoncus, neque dolor vulputate eros, non pellentesque elit lacus ut nunc. Pellentesque vel purus libero, ultrices condimentum lorem. Nam dictum faucibus mollis. Praesent adipiscing nunc sed dui ultricies molestie. Quisque facilisis purus quis felis molestie ut accumsan felis ultricies. Curabitur euismod est id est pretium accumsan. Praesent a mi in dolor feugiat vehicula quis at elit. Mauris lacus mauris, laoreet non molestie nec, adipiscing a nulla. Nullam rutrum, libero id pellentesque tempus, erat nibh ornare dolor, id accumsan est risus at leo. In convallis felis at eros condimentum adipiscing aliquam nisi faucibus. Integer arcu ligula, porttitor in fermentum vitae, lacinia nec dui.
EOT
);
fclose($stdin);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
4).
Script
array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/htmp2txt.log", "a") // stderr is a file to write to
);
$process = proc_open('lynx -stdin -dump 2>&1', $descriptorspec, $pipes, '/tmp', NULL);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to htmp2txt.log
$stdin = $pipes[0];
fwrite($stdin, <<<'EOT'
TEST
Lorem Ipsum
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et sapien ut erat porttitor suscipit id nec dui. Nam rhoncus mauris ac dui tristique bibendum. Aliquam molestie placerat gravida. Duis vitae tortor gravida libero semper cursus eu ut tortor. Nunc id orci orci. Suspendisse potenti. Phasellus vehicula leo sed erat rutrum sed blandit purus convallis.
Aliquam feugiat, neque a tempus rhoncus, neque dolor vulputate eros, non pellentesque elit lacus ut nunc. Pellentesque vel purus libero, ultrices condimentum lorem. Nam dictum faucibus mollis. Praesent adipiscing nunc sed dui ultricies molestie. Quisque facilisis purus quis felis molestie ut accumsan felis ultricies. Curabitur euismod est id est pretium accumsan. Praesent a mi in dolor feugiat vehicula quis at elit. Mauris lacus mauris, laoreet non molestie nec, adipiscing a nulla. Nullam rutrum, libero id pellentesque tempus, erat nibh ornare dolor, id accumsan est risus at leo. In convallis felis at eros condimentum adipiscing aliquam nisi faucibus. Integer arcu ligula, porttitor in fermentum vitae, lacinia nec dui.
EOT
);
fclose($stdin);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
5 không có tùy chọn để ẩn hoặc nhóm các liên kết ở cuối văn bản, làm cho một trang HTML thông thường trông đầy rẫy các liên kết khi ở định dạng toàn văn; Tùy chỉnh mã để xử lý đặc biệt về cách chuyển đổi được thực hiện không phải là thẳng như chỉ đơn giản là chỉnh sửa một mảng trong
Nếu bạn muốn một cái gì đó nâng cao hơn, bạn có thể phân tích các nút, nhưng bạn sẽ gặp nhiều vấn đề với khoảng trắng.
Tôi đã thực hiện một bộ chuyển đổi dựa trên những gì tôi nói ở đây. Nếu bạn quan tâm, bạn có thể tải xuống từ git https://github.com/kranemora/html2text
Nó có thể phục vụ như một tài liệu tham khảo để làm cho của bạn
Đã trả lời ngày 16 tháng 5 năm 2012 lúc 21:17May 16, 2012 at 21:17
Sudipsudipsudip
2.6591 Huy hiệu vàng29 Huy hiệu bạc40 Huy hiệu đồng1 gold badge29 silver badges40 bronze badges
1
Nếu bạn không muốn tước hoàn toàn các thẻ và giữ nội dung bên trong các thẻ, bạn có thể sử dụng
array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/htmp2txt.log", "a") // stderr is a file to write to
);
$process = proc_open('lynx -stdin -dump 2>&1', $descriptorspec, $pipes, '/tmp', NULL);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to htmp2txt.log
$stdin = $pipes[0];
fwrite($stdin, <<<'EOT'
TEST
Lorem Ipsum
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et sapien ut erat porttitor suscipit id nec dui. Nam rhoncus mauris ac dui tristique bibendum. Aliquam molestie placerat gravida. Duis vitae tortor gravida libero semper cursus eu ut tortor. Nunc id orci orci. Suspendisse potenti. Phasellus vehicula leo sed erat rutrum sed blandit purus convallis.
Aliquam feugiat, neque a tempus rhoncus, neque dolor vulputate eros, non pellentesque elit lacus ut nunc. Pellentesque vel purus libero, ultrices condimentum lorem. Nam dictum faucibus mollis. Praesent adipiscing nunc sed dui ultricies molestie. Quisque facilisis purus quis felis molestie ut accumsan felis ultricies. Curabitur euismod est id est pretium accumsan. Praesent a mi in dolor feugiat vehicula quis at elit. Mauris lacus mauris, laoreet non molestie nec, adipiscing a nulla. Nullam rutrum, libero id pellentesque tempus, erat nibh ornare dolor, id accumsan est risus at leo. In convallis felis at eros condimentum adipiscing aliquam nisi faucibus. Integer arcu ligula, porttitor in fermentum vitae, lacinia nec dui.
EOT
);
fclose($stdin);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
7 và trích xuất
array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/htmp2txt.log", "a") // stderr is a file to write to
);
$process = proc_open('lynx -stdin -dump 2>&1', $descriptorspec, $pipes, '/tmp', NULL);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to htmp2txt.log
$stdin = $pipes[0];
fwrite($stdin, <<<'EOT'
TEST
Lorem Ipsum
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et sapien ut erat porttitor suscipit id nec dui. Nam rhoncus mauris ac dui tristique bibendum. Aliquam molestie placerat gravida. Duis vitae tortor gravida libero semper cursus eu ut tortor. Nunc id orci orci. Suspendisse potenti. Phasellus vehicula leo sed erat rutrum sed blandit purus convallis.
Aliquam feugiat, neque a tempus rhoncus, neque dolor vulputate eros, non pellentesque elit lacus ut nunc. Pellentesque vel purus libero, ultrices condimentum lorem. Nam dictum faucibus mollis. Praesent adipiscing nunc sed dui ultricies molestie. Quisque facilisis purus quis felis molestie ut accumsan felis ultricies. Curabitur euismod est id est pretium accumsan. Praesent a mi in dolor feugiat vehicula quis at elit. Mauris lacus mauris, laoreet non molestie nec, adipiscing a nulla. Nullam rutrum, libero id pellentesque tempus, erat nibh ornare dolor, id accumsan est risus at leo. In convallis felis at eros condimentum adipiscing aliquam nisi faucibus. Integer arcu ligula, porttitor in fermentum vitae, lacinia nec dui.
EOT
);
fclose($stdin);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
Một lợi thế của phương pháp này là nó không yêu cầu bất kỳ gói bên ngoài nào.
Đã trả lời ngày 2 tháng 4 năm 2018 lúc 17:02Apr 2, 2018 at 17:02
Supersansupersansupersan
5.2642 Huy hiệu vàng41 Huy hiệu bạc61 Huy hiệu Đồng2 gold badges41 silver badges61 bronze badges
Làm cách nào để chuyển đổi HTML thành văn bản bình thường?
Lưu trang web dưới dạng tệp trang web (. HTM hoặc. Tiện ích mở rộng tệp HTML) ...
Nhấp lại tab Tệp, sau đó nhấp vào tùy chọn Lưu dưới dạng ..
Trong danh sách lưu xuống dưới dạng loại, chọn tùy chọn văn bản đơn giản (*. TXT). ....
Nhấp vào nút Lưu để lưu dưới dạng tài liệu văn bản ..
Tôi có thể chuyển đổi HTML thành PHP không?
Chỉ cần thay đổi tiện ích mở rộng tệp .html thành .php (index. HTML thành index.change file extension .html to .php (index. html to index.
Làm cách nào để hiển thị thẻ HTML dưới dạng văn bản đơn giản trong PHP?
Phương pháp 1: Sử dụng hàm htmlspecialchars (): hàm htmlspecialchars () là hàm sẵn trong PHP được sử dụng để chuyển đổi tất cả các ký tự được xác định trước thành các thực thể HTML.$ String: Tham số này được sử dụng để giữ chuỗi đầu vào.$ Flags: Tham số này được sử dụng để giữ các cờ.Using htmlspecialchars() function: The htmlspecialchars() function is an inbuilt function in PHP which is used to convert all predefined characters to HTML entities. $string: This parameter is used to hold the input string. $flags: This parameter is used to hold the flags.
Làm cách nào để hiển thị thẻ HTML dưới dạng văn bản đơn giản trong HTML?
Về cơ bản, có hai phương thức để hiển thị thẻ HTML dưới dạng văn bản đơn giản ...
Sử dụng phần tử: Phần tử plaintext không được dùng để có nghĩa là tính năng này không còn được hỗ trợ.....
HTML entities: The second and only option available is using html entities. < ,>.