1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PHP sprintf関数の意味・動作

Last updated at Posted at 2022-10-11

なかなか使う機会がなく知らなかったのでメモ。

PHPマニュアル

sprintf

説明:

sprintf(string $format, mixed ...$values): string

フォーマット文字列 format に基づき生成された文字列を返します。

$example .= sprintf("<a href=\"%s?hoge=%s&fuga=%s&foo=%s&baz=%s\" class=\"%s\">", "hoge", $fuga, $foo, $baz, $boo, $bar);

自分なりの理解
$fromatの中身の%の数分$valuesを渡す。
n番目の%に置換される文字列が$valuesのn番目のあたる引数。

%sみたいなのは指定子でsの場合は引数を文字列で扱う。
%sの場合は引数を文字列として置換する。

1
0
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?