2

文字列を読み取って変数 (タグ) を見つけ、それを保存された値に置き換える必要があります。タグを識別するために % (パーセント) を使用しました。入力は %color% や %animal% などのタグを受け入れる必要があるため、PHP では実際の文字列を挿入する必要があります...コードでよりよく説明されています:

// We have some strings stored
$color = 'white';
$animal = 'cat';

ユーザーは、必要な変数を表示するためにテキストエリアで %color%、%animal%、または何も使用しない必要があります。

// The user text was stored by the $text
$text = "The quick %color% fox jumps over the lazy %animal%.";

$text の %color% と %animal% は、$color と $animal の値に置き換える必要があります。しかし、どうすればそれができますか?最終的な出力は

<p>The quick white fox jumps over the lazy cat.</p>

WordPress では、ユーザーが「パーマリンク」オプションでこれを行うことができるため、ユーザーは、たとえば次の抽出を設定できます。

http://localhost/site/%category%/%postname%/
4

3 に答える 3