0
PHP中有一種簡單的方法來確定內置函數的源代碼/內容嗎?如何在PHP中查看內置函數的源代碼/內容?
舉例來說,我想知道base64_decode()
實際上對給定的編碼base64字符串做了什麼以將其轉換爲純文本。我怎樣才能做到這一點?
PHP中有一種簡單的方法來確定內置函數的源代碼/內容嗎?如何在PHP中查看內置函數的源代碼/內容?
舉例來說,我想知道base64_decode()
實際上對給定的編碼base64字符串做了什麼以將其轉換爲純文本。我怎樣才能做到這一點?
您可以瀏覽PHP here
的源代碼在你的情況base64_decode
實現here (PHP 5.6.0)
注:此代碼是用C,因爲這就是PHP寫的其實所有的內置功能。和PHP擴展C語言編寫的
PHPAPI unsigned char *php_base64_decode_ex(const unsigned char *str, int length, int *ret_length, zend_bool strict) /* {{{ */
{
const unsigned char *current = str;
int ch, i = 0, j = 0, k;
/* this sucks for threaded environments */
unsigned char *result;
result = (unsigned char *)safe_emalloc(length, 1, 1);
/* run through the whole string, converting as we go */
while ((ch = *current++) != '\0' && length-- > 0) {
if (ch == base64_pad) {
if (*current != '=' && ((i % 4) == 1 || (strict && length > 0))) {
if ((i % 4) != 1) {
while (isspace(*(++current))) {
continue;
}
if (*current == '\0') {
continue;
}
}
efree(result);
return NULL;
}
continue;
}
ch = base64_reverse_table[ch];
if ((!strict && ch < 0) || ch == -1) { /* a space or some other separator character, we simply skip over */
continue;
} else if (ch == -2) {
efree(result);
return NULL;
}
switch(i % 4) {
case 0:
result[j] = ch << 2;
break;
case 1:
result[j++] |= ch >> 4;
result[j] = (ch & 0x0f) << 4;
break;
case 2:
result[j++] |= ch >>2;
result[j] = (ch & 0x03) << 6;
break;
case 3:
result[j++] |= ch;
break;
}
i++;
}
k = j;
/* mop things up if we ended on a boundary */
if (ch == base64_pad) {
switch(i % 4) {
case 1:
efree(result);
return NULL;
case 2:
k++;
case 3:
result[k] = 0;
}
}
if(ret_length) {
*ret_length = j;
}
result[j] = '\0';
return result;
}
我有這個書籤:http://lxr.php.net/甚至esier你:HTTP://lxr.php.net/xref/PHP_5_5/ext /standard/base64.c#240 - http://lxr.php.net/xref/PHP_5_5/ext/standar d/base64.c#php_base64_decode_ex – 2014-09-02 20:22:13
什麼是一個很好的資源。非常感謝@Dagon正是我在尋找的東西 – 2014-09-02 20:23:50