-
-
Save millken/653188 to your computer and use it in GitHub Desktop.
| editplus正则查找php函数 | |
| ^[ \t]*(public |private |protected |static )[ \t]*(static[ \t]*)?function[ \t].*\([^;]*$ | |
| preg_match_all("~href=\"([^\"]+\.css)(?:.*?)\"[^>]*>~isx",$html,$links); 捕获html的link style链接 | |
| function get_all_url($code){ | |
| preg_match_all('/<as+href=["|']?([^>"' ]+)["|']?s*[^>]*>([^>]+)</a>/i',$code,$arr); | |
| return array('name'=>$arr[2],'url'=>$arr[1]); | |
| } | |
| /*======================================================================*\ | |
| Function: _expandlinks | |
| Purpose: expand each link into a fully qualified URL | |
| Input: $links the links to qualify | |
| $URI the full URI to get the base from | |
| Output: $expandedLinks the expanded links | |
| \*======================================================================*/ | |
| function _expandlinks($links,$URI) | |
| { | |
| preg_match("/^[^\?]+/",$URI,$match); | |
| $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]); | |
| $match = preg_replace("|/$|","",$match); | |
| $match_part = parse_url($match); | |
| $match_root = | |
| $match_part["scheme"]."://".$match_part["host"]; | |
| $search = array( "|^http://".preg_quote($this->host)."|i", | |
| "|^(\/)|i", | |
| "|^(?!http://)(?!mailto:)|i", | |
| "|/\./|", | |
| "|/[^\/]+/\.\./|" | |
| ); | |
| $replace = array( "", | |
| $match_root."/", | |
| $match."/", | |
| "/", | |
| "/" | |
| ); | |
| $expandedLinks = preg_replace($search,$replace,$links); | |
| return $expandedLinks; | |
| } |
preg_match_all("/url(\s_(?:["'])?(._?)\s*(?:["'])?)/isx", $c, $imagesURLArray); ?:表示不存储 ?表示0,1
preg_match_all("/src=(?:["'])([^'\"]+)/i", $cssContent, $imagesURLArray);
匹配CSS里的图片
$c = file_get_contents('meituan.css');
preg_match_all("/url(\s_(?:["'])?(._?)\s*(?:["'])?)|src=(?:["'])([^'\"]+)/isx", $c, $imagesURLArray);
$imagesURLArray = array_unique(array_filter(array_merge((array)$imagesURLArray[1], $imagesURLArray[2])));
usort($imagesURLArray, "cmp");
function cmp($a, $b) {
if (strlen($a) == strlen($b)) {
return 0;
}
return (strlen($a) > strlen($b)) ? -1 : 1;
}
d($imagesURLArray);
PHP完美的提取链接正则
今天把Snoopy里的提取链接函数挖出来,并加强了一下
function match_links($document) {
preg_match_all("'<\s_a\s.?href\s=\s_(["'])?(?(1)(.?)\1|([^\s>]+))[^>]>?(.*?)'isx",$document,$links);
while(list($key,$val) = each($links[2])) {
if(!empty($val))
$match['link'][] = $val;
}
while(list($key,$val) = each($links[3])) {
if(!empty($val))
$match['link'][] = $val;
}
while(list($key,$val) = each($links[4])) {
if(!empty($val))
$match['content'][] = $val;
}
while(list($key,$val) = each($links[0])) {
if(!empty($val))
$match['all'][] = $val;
}
return $match;
}
editplus 正则查找所有注释行
^[\t ]*[//|\/\*|*].*\n
komodo正则替换smarty变量
<{($.*)}>
preg_match_all("~href="([^\"]+.css)(?:.?)"[^>]>~isx",$html,$links); 捕获html的link style链接