php ile html parse

1 Cevap

facebook üzerinde çalışırken bağlarken ben (o url kendisi ama bu url kaplı dosyasında değil) bir url bir erişim belirteci almak zorunda böylece bu ben ne olduğunu

$url = "https://graph.facebook.com/oauth/access_token?client_id=".$facebook_app_id."&redirect_uri=http://www.example.com/facebook/oauth/&client_secret=".$facebook_secret."&code=".$code;"

function get_string_between($string, $start, $end){ 
    $string = " ".$string; 
    $ini = strpos($string,$start); 
    if ($ini == 0) return ""; 
    $ini += strlen($start); 
    $len = strpos($string,$end,$ini) - $ini; 
    return substr($string,$ini,$len); 
} 


$access_token = get_string_between(file_get_contents($url), "access_token=", "&expires=");  

bunu yapmak için daha iyi bir yolu yoktur çirkin ve beceriksiz görünüyor? teşekkür ederim.

1 Cevap

Sen PHP fonksiyonunu kullanabilirsiniz parse_str

"https://graph.facebook.com/oauth/access_token?client_id=".$facebook_app_id."&redirect_uri=http://www.example.com/facebook/oauth/&client_secret=".$facebook_secret."&code=".$code;

parse_str(file_get_contents($url));

echo $access_token;

PHP manuel: (link)

void parse_str (string $ str [, array & $ dizi])

Parses str as if it were the query string passed via a URL and sets variables in the current scope.