我遇到問題,使用substr()
來自正則表達式的匹配(使用preg_match()
- $a
包含匹配數組)。PHP的substr()不工作時,第三parem是字符串像0xe84?
當echo'ing a[1]
它等於0xe84
並且是一個字符串(因爲我使用gettype()
檢查)。
substr($file, $a[2], $a[1]); //not working...
但如果我這樣做(另請注意,我不能真正做到這一點作爲第三parem是通用從一個正則表達式來 - 這僅僅是用來說明我的問題):
substr($file, $a[2], 0xe84); //works fine - when entering the match directly as an integer
所以我的問題是爲什麼substr()
只有當第三parem是一個整數類型,我怎樣才能讓$a[1]
一個整數,所以它工作正常?
我試着做類型轉換(使用(int)
),在$a[1]
使用intval()
以及settype(integer)
,但是$a[1]
就變成0
(和substr()
將無法正常工作)。
太好了,我的工作原理就是這樣!只是很高興有人能理解我的問題。 – newbtophp 2011-01-06 21:40:44