从源代码获取preg_match的哈希值

时间:2016-03-14 02:59:47

标签: php preg-match

我想从链接源代码中获取哈希并将其存储在变量中 源代码是:

Profile.init({"user_id":37462,"loc":null,"back":"Leeter Leeter","last_names":[],"max_name_len":280,"hash_hash":"8cc8f7b2dcb4331676"});

我想要的哈希是:8cc8f7b2dcb4331676

我试过这段代码,但它没有用。

<?php
$data = file_get_contents("Link");
if (preg_match("/hash_hash":"([a-zA-Z0-9]+)"/i", $data, $matches))
     print "The hash is: $matches[1]";
else
     print "The page doesn't have a hash";

1 个答案:

答案 0 :(得分:1)

您可以在preg_match_all()中使用以下模式:

'/"hash_hash":"([^"]+)"/i'

示例:

$x='Profile.init({"user_id":37462,"loc":null,"back":"Leeter Leeter","last_names":[],"max_name_len":280,"hash_hash":"8cc8f7b2dcb4331676"})';
preg_match_all('/"hash_hash":"([^"]+)"/i',$x,$matches);
print_r($matches[1]);

演示:https://eval.in/535936