parsing through html with php

Posted by salmane on Stack Overflow See other posts from Stack Overflow or by salmane
Published on 2010-05-13T11:49:41Z Indexed on 2010/05/13 11:54 UTC
Read the original article Hit count: 190

Filed under:

while working on facebook connect I have to retrieve an access token from a url ( it is not in the url itself but in the file lined to that url) so this is what I do

$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=");  

it looks ugly and clumsy is there a better way to do it ? thank you .

© Stack Overflow or respective owner

Related posts about php