wiki:trim_the_ed2k_link
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312"/> <title>trim ed2k link</title> </head> <body> <table witdh="90%"> <tr><td> <?php function Strip($link) { $str = $link; $str = str_replace("..", ".", $str); $str = str_replace("..", ".", $str); $str = str_replace("..", ".", $str); $str = str_replace("|.", "|", $str); $str = str_replace(".|", "|", $str); return $str; } if ($_POST["submit"] != "") { $content = ""; $url = $_POST["url"]; if ($url != "") { $fp = fopen($url, "r"); if ($fp) { while (!feof($fp)){ $buf = fgets($fp); $content = $content.$buf; unset($buf); } fclose($fp); } } if ($content != "") { if (preg_match ("#charset=(.*)[\"|/| ]#iU", $content, $matches)) $charset = $matches[1]; else $charset = "GB2312"; $content = iconv($charset, "gb2312//IGNORE", $content); $content = preg_replace("#(%5B)#iU", "[", $content); $content = preg_replace("#(%5D)#iU", "]", $content); $content = preg_replace("#(%7C)#iU", "|", $content); $content = preg_replace("#(%[0-9A-F][0-9A-F])#iU", "", $content); if ($content != "") { //echo $content."<br><br>\n\n"; preg_match_all("#ed2k://(.*)/#iU", $content, $matches); $st = ""; foreach ($matches[1] as $match) { if ($st == $match) continue; $st = $match; // strip chinese characters $match = preg_replace("#(%7C)#iU", "|", urlencode($match)); $match = preg_replace("#(%[0-9A-F][0-9A-F])#iU", "", $match); echo "ed2k://".Strip($match)."/"."<br>\n"; } } } } else { echo "<form name=frm method=post action=ek.php><table><tr><td>". "URL:<input type=text name=url size=40 value=>". "<input type=submit name=submit value=Parse>". "<input type=reset name=reset value=Reset>". "</td></tr></table></form>"; } ?> </td></tr> </table> </body> </html>
wiki/trim_the_ed2k_link.txt · Last modified: 2007/11/25 03:40 by mirnshi