{"id":8073,"date":"2019-12-05T10:00:45","date_gmt":"2019-12-05T01:00:45","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=8073"},"modified":"2019-12-05T10:01:54","modified_gmt":"2019-12-05T01:01:54","slug":"php-printf-sprintf-vprintf-vsprintf%e3%80%80%e3%81%ae%e9%81%95%e3%81%84%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6%ef%bc%88%e3%81%9d%e3%81%ae2%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/8073","title":{"rendered":"[php] printf sprintf vprintf vsprintf\u3000\u306e\u9055\u3044\u306b\u3064\u3044\u3066\uff08\u305d\u306e2\uff09"},"content":{"rendered":"\n<p>PHP\u3067\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3057\u305f\u6587\u5b57\u5217\u306e\u51fa\u529b\u3092\u304a\u3053\u306a\u3046\u969b\u306b\u4f7f\u7528\u3059\u308b\u95a2\u6570\u3001<br> printf sprintf vprintf vsprintf\u3000\u306e\u4f7f\u3044\u5206\u3051\u306b\u3064\u3044\u3066\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u4eca\u56de\u306f\u300csprintf\u300d\u304a\u3088\u3073\u300cvsprintf\u300d\u306e\u4f7f\u7528\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<br> \u300cprintf\u300d\u300csprintf\u300d\u306e\u4f7f\u7528\u65b9\u6cd5\u306f<a href=\"\/appnews\/archives\/8037\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"\u524d\u56de\u306e\u8a18\u4e8b (\u65b0\u3057\u3044\u30bf\u30d6\u3067\u958b\u304f)\">\u524d\u56de\u306e\u8a18\u4e8b<\/a>\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h3>sprintf\u306e\u4f7f\u7528\u65b9\u6cd5\u306e\u4f8b\uff1a<\/h3>\n\n\n\n<p>sprintf\u306fprintf\u306b\u3088\u304f\u4f3c\u3066\u3044\u307e\u3059\u304c\u3001<br> printf \u306f\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u6e08\u307f\u306e\u6587\u5b57\u5217\u3092\u51fa\u529b\u3059\u308b\u306e\u306b\u5bfe\u3057\u3066\u3001<br> sprintf \u306f\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3055\u308c\u305f\u6587\u5b57\u5217\u3092\u8fd4\u3057\u307e\u3059\u3002<br><br> sprintf\u5358\u4f53\u3067\u306f\u51fa\u529b\u3057\u307e\u305b\u3093\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f<br> sprintf\u304b\u3089\u53d7\u3051\u53d6\u3063\u305f\u6587\u5b57\u5217\u3092echo\u3067\u51fa\u529b\u3092\u304a\u3053\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$format = \"\u540d\u524d\u306f\u3001%s\u3067\u3001\u5e74\u9f62\u306f%d\u3067\u3059\u3002&lt;br\/>\";\n$hoge1 = sprintf($format,  \"\u5c71\u7530\u592a\u90ce\",  30);\n$hoge2 = sprintf($format,  \"\u5927\u962a\u82b1\u5b50\",  20);\necho $hoge1;\necho $hoge2;<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306e\u51fa\u529b\u7d50\u679c\uff1a<br><strong> \u540d\u524d\u306f\u3001\u5c71\u7530\u592a\u90ce\u3067\u3001\u5e74\u9f62\u306f30\u3067\u3059\u3002<br> \u540d\u524d\u306f\u3001\u5927\u962a\u82b1\u5b50\u3067\u3001\u5e74\u9f62\u306f20\u3067\u3059\u3002<\/strong><\/p>\n\n\n\n<p>\u307e\u305f\u5f15\u6570\u3067\u53d7\u3051\u53d6\u3063\u305f\u5024\u3092\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u51fa\u529b\u3059\u308b\u6587\u5b57\u5217\u5185\u306b\u8907\u6570\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001<br> \u5f15\u6570\u306e\u756a\u53f7\u3092\u6307\u5b9a\u3057\u3066\u8907\u6570\u56de\u4f7f\u3044\u56de\u3059\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p> \u305d\u306e\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$age = 50;\n$name = '\u5c71\u7530';\n$format = '\u540d\u524d\u306f %2$s \u3067\u3059\u3002\u5e74\u9f62\u306f %1$d \u3067\u3059\u3002&lt;br \/>\n           \u5e74\u9f62\u306f %1$d\u306e %2$s \u3067\u3059\u3002';\necho sprintf($format, $age, $name);<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306e\u51fa\u529b\u7d50\u679c\uff1a<br><strong> \u540d\u524d\u306f \u5c71\u7530 \u3067\u3059\u3002\u5e74\u9f62\u306f 50 \u3067\u3059\u3002<br> \u5e74\u9f62\u306f 50\u306e \u5c71\u7530 \u3067\u3059\u3002<\/strong><\/p>\n\n\n\n<h3>vsprintf\u306e\u4f7f\u7528\u65b9\u6cd5\u306e\u4f8b\uff1a<\/h3>\n\n\n\n<p>vsprintf \u306f\u3001sprintf \u3068\u52d5\u4f5c\u306f\u540c\u3058\u3067\u3059\u304c\u3001 <br> \u53ef\u5909\u9577\u306e\u5f15\u6570\u3067\u306f\u306a\u304f\u914d\u5217\u304c\u5f15\u6570\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p> \u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$array1 = array(\"\u5c71\u7530\u592a\u90ce\", 30);\n$array2 = array(\"\u5927\u962a\u82b1\u5b50\", 20);\n$format = \"\u540d\u524d\u306f\u3001%s\u3067\u3001\u5e74\u9f62\u306f%d\u3067\u3059\u3002&lt;br\/>\";\n$hoge1 = vsprintf($format,  $array1);\n$hoge2 = vsprintf($format,  $array2);\necho $hoge1;\necho $hoge2;<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306e\u51fa\u529b\u7d50\u679c\uff1a<br><strong> \u540d\u524d\u306f\u3001\u5c71\u7530\u592a\u90ce\u3067\u3001\u5e74\u9f62\u306f30\u3067\u3059\u3002<br> \u540d\u524d\u306f\u3001\u5927\u962a\u82b1\u5b50\u3067\u3001\u5e74\u9f62\u306f20\u3067\u3059\u3002<\/strong><\/p>\n\n\n\n<p>\u3053\u3061\u3089\u3082vsprintf\u3067\u53d7\u3051\u53d6\u3063\u305f\u914d\u5217\u306e\u5f15\u6570\u3092\u8907\u6570\u56de\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001<br> \u5f15\u6570\u306e\u756a\u53f7\u3092\u6307\u5b9a\u3057\u3066\u4f7f\u3044\u56de\u3059\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$array1 = array(30,\"\u5c71\u7530\u592a\u90ce\");\n$array2 = array(20,\"\u5927\u962a\u82b1\u5b50\");\n$format = '\u540d\u524d\u306f %2$s \u3067\u3059\u3002\u5e74\u9f62\u306f %1$d \u3067\u3059\u3002&lt;br \/>\n           \u5e74\u9f62\u306f %1$d\u306e %2$s \u3067\u3059\u3002&lt;br \/>';\n$hoge1 = vsprintf($format,  $array1);\n$hoge2 = vsprintf($format,  $array2);\necho $hoge1;\necho $hoge2;<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306e\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n\n\n\n<p><strong>\u540d\u524d\u306f \u5c71\u7530\u592a\u90ce \u3067\u3059\u3002\u5e74\u9f62\u306f 30 \u3067\u3059\u3002<br> \u5e74\u9f62\u306f 30\u306e \u5c71\u7530\u592a\u90ce \u3067\u3059\u3002<br> \u540d\u524d\u306f \u5927\u962a\u82b1\u5b50 \u3067\u3059\u3002\u5e74\u9f62\u306f 20 \u3067\u3059\u3002<br> \u5e74\u9f62\u306f 20\u306e \u5927\u962a\u82b1\u5b50 \u3067\u3059\u3002<\/strong><\/p>\n\n\n\n<p>\u6728\u66dc\u65e5\u62c5\u5f53\uff1anishida<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8073\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/8073\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"[php] printf sprintf vprintf vsprintf\u3000\u306e\u9055\u3044\u306b\u3064\u3044\u3066\uff08\u305d\u306e2\uff09\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8073\" data-text=\"[php] printf sprintf vprintf vsprintf\u3000\u306e\u9055\u3044\u306b\u3064\u3044\u3066\uff08\u305d\u306e2\uff09\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8073\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8073\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u3067\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3057\u305f\u6587\u5b57\u5217\u306e\u51fa\u529b\u3092\u304a\u3053\u306a\u3046\u969b\u306b\u4f7f\u7528\u3059\u308b\u95a2\u6570\u3001 printf sprintf vprintf vsprintf\u3000\u306e\u4f7f\u3044\u5206\u3051\u306b\u3064\u3044\u3066\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8073"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=8073"}],"version-history":[{"count":18,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8073\/revisions"}],"predecessor-version":[{"id":8092,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8073\/revisions\/8092"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=8073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=8073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=8073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}