我想這樣做,以便如果從$hello
輸入$words
它們被替換爲bonjour但它不起作用。我該如何去做這件事?我如何讓替換工作,因爲我打算在PHP中?
代碼:
<?php
$words = $_POST['words'];
$hello = array('hello', 'hi', 'yo', 'sup');
$words = preg_replace('/\b'.$hello.'\b/i', '<span class="highlight">Bonjour</span>', $words);
echo $words;
?>
你試圖使用'$ hello'作爲一個字符串,如果它是一個數組:你雖然可以破滅這一點,有點像!我建議在[php bible](http://php.net)中尋找'for'和'foreach'。 – Dale 2013-02-19 13:18:23