0
好吧內搜索,我感覺在這裏遲鈍,字符串數組
我有像這樣的字符串:
$string = 'function module_testing() {';
,也可能是這樣的:
$string = 'function module_testing()';
或者它可能是這樣的:
$string = 'function module_testing($params) {';
或本:
$string = 'function module_testing($params, $another = array())';
,還有更多的方式...
而且比我有一個字符串數組,像這樣:
$string_array = array('module_testing', 'another_function', 'and_another_function');
現在,有某種preg_match
,我可以在任何給定位置測試$string
字符串中是否存在任何$string_array
值?所以在這種情況下,會有一場比賽。還是有更好的方法來做到這一點?
我不能使用in_array
,因爲它不是一個精確匹配,和我寧願不去做就可以了foreach
循環,如果我能幫助它,因爲它已經在while
循環。
謝謝:)
那麼,在這種情況下,它只有3個值,但實際上並不總是如此... – SoLoGHoST 2010-05-02 05:29:51
'stristr',那會有幫助嗎? – SoLoGHoST 2010-05-02 05:30:51
@SoLoG在這種情況下,'strstr()'與使用'strpos()'沒有多大區別。 – cletus 2010-05-02 05:33:14