entities.php
27 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Fetch the entities.json file and convert to PHP datastructure. |
| 4 | */ |
| 5 | |
| 6 | // The URL to the official entities JSON file. |
| 7 | $ENTITIES_URL = 'http://www.w3.org/TR/2012/CR-html5-20121217/entities.json'; |
| 8 | |
| 9 | $payload = file_get_contents($ENTITIES_URL); |
| 10 | $json = json_decode($payload); |
| 11 | |
| 12 | $table = array(); |
| 13 | foreach ($json as $name => $obj) { |
| 14 | $sname = substr($name, 1, -1); |
| 15 | $table[$sname] = $obj->characters; |
| 16 | } |
| 17 | |
| 18 | echo '<?php |
| 19 | namespace Masterminds\\HTML5; |
| 20 | /** Entity lookup tables. This class is automatically generated. */ |
| 21 | class Entities { |
| 22 | public static $byName = '; |
| 23 | var_export($table); |
| 24 | echo '; |
| 25 | }' . PHP_EOL; |
| 26 | //print serialize($table); |
| 27 |