0

PHPの日付フォーマット関数は次のとおりです。

function formatMyDateNicely($strTimeString) {
    return date('F j, y \a\t g:iA', strtotime($strTimeString));   
}

「12 年 4 月 23 日午後 12 時 1 分」のような日付を出力します。

ただし、二重引用符を使用するこの関数は機能しません。

function formatMyDateNicely($strTimeString) {
    return date("F j, y \a\t g:iA", strtotime($strTimeString));   
}

この関数は、「4 月 23 日 12 日午後 12 時 1 分」のような日付を出力します。

引用符の種類の変更が重要なのはなぜですか?

4

2 に答える 2

6

\t is a tab character. Single quotes inhibit interpretation of escape sequences.

于 2012-05-01T03:38:08.793 に答える
2

It's treating the \t as a tab character because of the double quotes. Another alternative would be to "double escape" the t:

return date("F j, y \a\\t g:iA", strtotime($strTimeString)); 
于 2012-05-01T03:39:55.210 に答える