我想測試一個字符串是否由多個單詞組成並且在數組的末尾有任何值。以下是我目前爲止的內容。我堅持如何檢查字符串是否比正在測試的數組值更長,並且它出現在字符串的末尾。檢查是否有任何數組值存在於字符串的末尾
$words = trim(preg_replace('/\s+/',' ', $string));
$words = explode(' ', $words);
$words = count($words);
if ($words > 2) {
// Check if $string ends with any of the following
$test_array = array();
$test_array[0] = 'Wizard';
$test_array[1] = 'Wizard?';
$test_array[2] = '/Wizard';
$test_array[4] = '/Wizard?';
// Stuck here
if ($string is longer than $test_array and $test_array is found at the end of the string) {
Do stuff;
}
}
這很好用!我添加了忽略情況,但這很簡單,並完成了工作。 'if(preg_match('〜/?Wizard \ $ $〜i',$ string)){' – Matthew 2011-06-05 15:42:50