使用PHP重新實現(xiàn)PHP腳本引擎內(nèi)置函數(shù)
來源:程序員人生 發(fā)布時間:2013-11-18 11:44:02 閱讀次數(shù):2714次
實在無聊,突發(fā)奇想,想把PHP里面部分已經(jīng)提供封裝好的函數(shù)重新使用PHP實現(xiàn)一遍,于是便有了下面的代碼主要實現(xiàn)了PHP中部分字符串處理函數(shù)。
同時實現(xiàn)了一些PHP中沒有,但是同樣有作用的字符串處理函數(shù)同樣的這些函數(shù),也能夠使用其他語言來實現(xiàn),比如用C/VBScript/Perl等等,那么你就能夠有一個自己的函數(shù)庫.以下函數(shù)不一定能夠成功運行,只是為了學(xué)習(xí)而已。
-
-
-
-
-
-
-
- function strlen1($str)
- {
- if ($str == '')
- return 0;
-
- $count = 0;
- while (1)
- {
- if ($str[$count] != NULL)
- {
- $count ;
- continue;
- }
- else
- break;
- }
- return $count;
- }
-
-
-
-
-
-
-
-
-
-
-
-
- function substr1($str, $start, $length=0)
- {
- if ($str == '')
- return;
- if ($start > strlen($str))
- return;
- if (($length != NULL) && ($start > 0) && ($length > strlen($str)-$start))
- return;
- if (($length != NULL) && ($start < 0) && ($length > strlen($str) $start))
- return;
-
- if ($length == NULL)
- $length = (strlen($str) - $start);
-
- if ($start < 0)
- {
- for ($i=(strlen($str) $start); $i<(strlen($str) $start $length); $i )
- {
- $substr .= $str[$i];
- }
- }
-
- if ($length > 0)
- {
- for ($i=$start; $i<($start $length); $i )
- {
- $substr .= $str[$i];
- }
- }
-
- if ($length < 0)
- {
- for ($i=$start; $i<(strlen($str) $length); $i )
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈