2016-03-14 60 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