-2
示例代碼提前使用STR的替換功能
$str = "some text <cs> some text </cs> some text <cs> some text </cs> some text <cs> some text </cs>";
$str = str_replace("<cs>", <textarea id="codeBlock">, $str);
$str = str_replace("</cs>", </textarea>, $str);
現在的問題是,它將所有<cs>
到<textarea id="codeBlock">
,我想那是什麼在$str
第一<cs>
應該得到id="codeBlock-1"
秒會得到id="codeBlock-2"
等等。
'str_replace'只是一個簡單的字符串替換的。對於這樣的事情,您可能需要使用[preg_replace_callback](https://php.net/preg_replace_callback)根據到目前爲止完成的替換次數返回一個動態值。 –