2016-03-14 26 views
1

我想从链接源代码的哈希和股票它在一个可变 的源代码获取哈希值是:从源代码的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"; 
+0

“链接” 是$数据=的file_get_contents(”链接“)只是一个字符串。 Profile.init来自哪里? –

回答

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