php 正则匹配指定url的参数
1 <?php 2 //清除特殊符号 3 function replace_specialChar($strParam){ 4 $regex = "/\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\ |\`|\-|\=|\\\|\|/"; 5 return preg_replace($regex,"",$strParam); 6 } 7 $str = "123~!@#$%^&*()_+{}:|<>?,./;'[]\-=`456"; 8 $str = replace_specialChar($str); 9 echo $str; 10 11 echo "<br>"; 12 13 //$str = "0512-62853677"; // result: 051262853677 14 $str = "+86 13764643510"; //8613764643510 15 $str = "120*"; 16 echo replace_specialChar($str);
function get_url_params($url, $arg_name) { $regx = '/.*[&|\?]'. $arg_name .'=([^&]*)(.*)/'; preg_match($regx, $url, $match); return $match[1]; } $str = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']; var_dump($str); //preg_match('/.*[&|\?]a=([^&]*)(.*)/', $str, $match); //var_dump($match); echo get_url_params($str, 'e'); $temp_str = 'http://xsimon.cn/mm/cc/mm.php?aa=11'; $token = strtok($temp_str, '?'); $pos = strrpos($token, '/'); $token = substr($token, 0, $pos+1); var_dump($token);