php獲取指定位置內(nèi)容
來源:程序員人生 發(fā)布時(shí)間:2014-01-01 16:14:13 閱讀次數(shù):2958次
這款函數(shù)比較實(shí)用于數(shù)據(jù)采集,一般采集數(shù)據(jù)時(shí)會(huì)要指定一個(gè)區(qū)域的內(nèi)容,這個(gè)代碼就可以實(shí)例:
- $str="<!-- fdaf-- -->";
- echo strip_comments( $str );
-
- function strip_comments($data) {
- $the_rest = $data;
- $result = "";
-
- while ($the_rest) {
- $start = strpos($the_rest, "<!--");
- if ($start === false) {
- $result .= $the_rest;
- break;
- }
-
- $result .= substr($the_rest, 0, $start);
-
- $end = strpos($the_rest, "-->", $start);
- if ($end === false) {
- break;
- }
-
- $the_rest = substr($the_rest, $end+3);
- }
-
- return $result;
- }
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)