php獲取指定位置內容
來源:程序員人生 發布時間:2014-01-01 16:14:13 閱讀次數:2974次
這款函數比較實用于數據采集,一般采集數據時會要指定一個區域的內容,這個代碼就可以實例:
- $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;
- }
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈