Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find/Replace htmlentities using the standard linux toolchain?

Is there a way I can do something like the following using the standard linux toolchain?

Let's say the source at example.com/index.php is:

Hello, & world! "

How can I do something like this...

curl -s http://example.com/index.php | htmlentities

...that would print the following:

Hello, & world! "

Using only the standard linux toolchain?

like image 494
Cam Avatar asked Jul 23 '10 22:07

Cam


2 Answers

Use recode.

$ echo 'Hello, & world! "' | recode HTML_4.0
Hello, & world! "

EDIT: By the way, recode offers several different conversions corresponding to different versions of HTML and XML, so you can use e.g. HTML_3.2 instead of HTML_4.0 if you have a really old HTML document. Running recode -l will list all the complete list of charsets supported by the program.

like image 183
David Z Avatar answered Oct 16 '22 19:10

David Z


alias decode="php -r 'echo html_entity_decode(fgets( STDIN ));'"

$ echo 'Hello, & world! "' | decode
Hello, & world! "
like image 20
Maryam Avatar answered Oct 16 '22 19:10

Maryam