Last active
January 22, 2019 10:55
-
-
Save zonuexe/a1ee5a136818a13c68e39a73423d6839 to your computer and use it in GitHub Desktop.
どうしてもPHPからHTMLを出力せざるを得なくなったときにご利用ください
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 | |
/** | |
* printf is template engine | |
* | |
* @license WTFPL http://www.wtfpl.net/ | |
* @author USAMI Kenta <[email protected]> | |
* @param string $format | |
* @param string|int|float $args... | |
* @return string | |
*/ | |
function htmlsprintf($format) | |
{ | |
return vsprintf($format, array_map( | |
function ($v) { return htmlspecialchars($v, ENT_QUOTES, 'UTF-8'); }, | |
func_get_args() | |
)); | |
} |
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 | |
$makelink = function ($id, $title) { | |
$url = sprintf('http://http://www.pixiv.net/member_illust.php?mode=medium&illust_id=%d', $id); | |
return htmlsprintf('<a href="%s">%d %s</a>', $id, $url, $title); | |
}; | |
?> | |
<title>htmlsprintf</title> | |
<div> | |
<?= $makelink(40246869, "うきうき & ももんが") ?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment