【发布时间】:2011-06-05 15:03:39
【问题描述】:
我正在尝试测试一个字符串是否由多个单词组成,并且是否在其末尾具有来自数组的任何值。以下是我到目前为止所拥有的。我被困在如何检查字符串是否比正在测试的数组值长并且它是否存在于字符串的末尾。
$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;
}
}
【问题讨论】:
标签: php arrays if-statement compare