function get_symbols($str, $reverse = false)
{
$symbols = array();
foreach (explode(' ', $str) as $word)
{
if ($reverse)
$word = strrev($word);
if (strlen($word) > 3)
$word = substr($word, 0, 3);
array_push($symbols, $word);
}
return $symbols;
}
編輯:
function change_reverse_symbol_in_word($str, $symbol, $replace_to)
{
$result = "";
foreach (explode(' ', $str) as $word)
{
$rword = $word;
if (strlen($rword) > 3)
{
$rword = substr($word, 0, -3);
}
if (!strcmp($symbol, $rword))
{
$word = substr($word, 0, strlen($word) - strlen($rword)) . $replace_to;
}
$result .= $word . " ";
}
return $result;
}
如果你想用這個像你的問題,你必須調用此類似:
$string_malformed = change_reverse_symbol_in_word($str, "ey", "ei");
當你說'每個單詞的符號'時,你的意思是什麼? – Svisstack 2010-08-09 21:59:52
「million」:「m,i,l」是前三個符號,「i,o,n」 - 最後3個符號 – James 2010-08-09 22:11:53
如果您使用「字母」而不是「符號」,則您的問題會立即更容易理解。 – meagar 2010-08-09 22:29:45