Last active
November 26, 2016 15:58
-
-
Save Lexx918/bf06e3c79f9bbd57fedb4c28905ae746 to your computer and use it in GitHub Desktop.
Emoji+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://unicode.org/emoji/charts-beta/full-emoji-list.html | |
$src = __DIR__ . "/emoji.html"; | |
$dest = __DIR__ . "/emoji+.html"; | |
$f = fopen($dest, "w"); | |
fwrite($f, "<html><head></head><body><table>"); | |
fwrite($f, "<tr> | |
<th>#</th> | |
<th>code</th> | |
<th>img</th> | |
<th>name</th> | |
<th>keywords</th> | |
<th>iWords</th> | |
</tr>"); | |
$dom = new DOMDocument(); | |
$internalErrors = libxml_use_internal_errors(true); | |
$dom->loadHTMLFile($src); | |
libxml_use_internal_errors($internalErrors); | |
$tableList = $dom->getElementsByTagName('table'); | |
foreach ($tableList as $table) ; | |
$i = 0; | |
$trList = $table->getElementsByTagName('tr'); | |
foreach ($trList as $trIndex => $tr) { | |
$tdList = $tr->getElementsByTagName('td'); | |
if (!($imgTd = $tdList->item(4))) { | |
continue; | |
} | |
$i++; | |
$code = $tdList->item(1)->getElementsByTagName('a')->item(0)->nodeValue; | |
$img = $imgTd->getElementsByTagName('img')->item(0); | |
$src = $img->getAttribute('src'); | |
$src = substr($src, 22); // data:image/png;base64, | |
$src = base64_decode($src); | |
file_put_contents(__DIR__ . "/emoji/{$i}.png", $src); | |
$name = $tdList->item(16)->nodeValue; | |
$keywords = $tdList->item(18)->nodeValue; | |
fwrite($f, "<tr> | |
<td>{$i}</td> | |
<td>{$code}</td> | |
<td><img src='emoji/{$i}.png'></td> | |
<td>{$name}</td> | |
<td>{$keywords}</td> | |
<td></td> | |
</tr>"); | |
if ($i > 20) { break; } | |
} | |
fwrite($f, "</table></body></html>"); | |
fclose($f); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment