[TxMt] Again: Text to HTML translation
Allan Odgaard
allan at macromates.com
Fri Nov 26 18:47:39 UTC 2004
On Nov 26, 2004, at 19:39, Allan Odgaard wrote:
> php -r '$a1 = array(); foreach(explode("<",
> stripslashes($_ENV["TM_SELECTED_TEXT"])) as $s1) { $a2 = array();
> foreach(explode(">", $s1) as $s2) array_push($a2, htmlentities($s2, 0,
> "UTF-8")); array_push($a1, implode(">", $a2)); } echo implode("<",
> $a1);'
Here's an update which takes text from stdin instead of using the
TM_SELECTED_TEXT variable:
php -r '$a1 = array(); foreach(explode("<",
file_get_contents("/dev/stdin")) as $s1) { $a2 = array();
foreach(explode(">", $s1) as $s2) array_push($a2, htmlentities($s2, 0,
"UTF-8")); array_push($a1, implode(">", $a2)); } echo implode("<",
$a1);'
I prefer this due to the apparent slash-mangling that PHP does and that
it then is more like a filter, e.g. the 'standard input' can be changed
to entire document etc.
More information about the textmate
mailing list