即時通訊開發一個測驗系統..替換字符串在PHP
讓說,我有這個字符串..
$my_string = "The language i use is [ans]php[/ans]";
,輸出是:
我使用的語言爲[輸入name ='ans'id ='ans'/] // Textbox by the way
我使用preg_replace函數但沒有運氣..
我的代碼:
$string = 'The quick [j]brown[/j] fox jumped over the lazy dog.';
$patterns = array();
$patterns[0] = '!\[j\]]';
$patterns[1] = '/brown/';
$patterns[2] = '\[/j\]!';
$replacements = array();
$replacements[0] = '';
$replacements[1] = '<input type="text" name="j_1" id="j_1" />';
$replacements[2] = '';
echo preg_replace($patterns, $replacements, $string);
產量爲:
The quick []<input type="text" name="j_1" id="j_1" /> [/] fox jumped over the lazy dog.
後市展望:
The quick <input type="text" name="j_1" id="j_1" /> fox jumped over the lazy dog.
很感激,如果你們能幫助..
感謝
這真的是你想要的輸出嗎? – alexn 2010-12-22 13:59:04
爲什麼不發佈您的代碼,以便我們可以嘗試找出什麼是錯誤的... – ircmaxell 2010-12-22 14:01:42