正則php
一套程式中需要在指定的URL頁面中提取裡面所有的網域名稱,現代碼如下:
$CODE = ......;//這裡是擷取遠端URL內容 $temp = "//i"; preg_match_all( $temp, $CODE, $Jzz_thlld ); $Jzz_thlld = $Jzz_thlld[0]; $temp = "/ href=[\"']?http:\\/\\/www\\.([^>\"' ]+)[\"']?\\s*[^>]*>(.*)<\\/a>/si"; for ($dos_skipping = 0; $dos_skipping < sizeof( $Jzz_thlld ); $dos_skipping++ ) { preg_match( $temp, $Jzz_thlld[$dos_skipping], $tempurl ); if ( !( $tempurl[1] != "" ) && !( strpos( $tempurl[1], "?" ) === FALSE ) && !( strpos( $tempurl[1], "&" ) === FALSE ) && !( strpos( $tempurl[1], "#" ) === FALSE ) && !( strpos( $tempurl[1], ":" ) === FALSE ) && !( strpos( $tempurl[1], " " ) === FALSE ) ) { echo '99'; $url_temp = "www.".$tempurl[1]; if ( 0 < strpos( $url_temp, "/" ) ) { $url_arr = explode( "/", $url_temp ); $url_temp = $url_arr[0]; } if ( $Jzz_cbgsf == "" ) { $Jzz_cbgsf = $url_temp; } else if ( strpos( "||".$Jzz_cbgsf."||", "||".$url_temp."||" ) === FALSE ) { $Jzz_cbgsf .= "||".$url_temp; } } }
上述代碼中不能按照需求萃取到所需要的資訊,忘各位幫忙看看,改如何修改!!