正则表达式获取pastebin.com的ID

时间:2011-07-29 00:51:11

标签: php regex

我需要获取pastebin链接的ID部分,

设置为http://pastebin.com/ {id},我已经厌倦了很多不同的正则表达式我也在php中使用preg_match

3 个答案:

答案 0 :(得分:2)

而不是正则表达式,请尝试使用parse_url来提取路径

答案 1 :(得分:2)

preg_match("~http://pastebin.com/([0-9a-zA-Z]+)~", $url, $match);
print_r($match);

$url = "http://pastebin.com/a65d46";
$parsed = parse_url($url);
echo trim($parsed['path'])." is ID you needed";

答案 2 :(得分:1)

正则表达式对此有点过分。

$url = "http://pastebin.com/Ugj1eqCN"
$pos = strpos($url,"pastebin.com/");
echo substr($url,$pos+13);
相关问题