2017-09-16 169 views
0

我正在使用php,并试图调用一个代码块内的函数,但我不知道为什么它会导致错误,但它是在稍后定义的。致命错误:调用未定义的函数,PHP

PHP代码

if(isset($_GET["updateRow"])){ 
 
    
 
      $_fbURL = $_GET["ajaxified"]; 
 
       
 
      if(!empty($_fbURL)){ 
 
        $url = $_fbURL; 
 
        $urlParts = explode("facebook.com/", $url); 
 
        $username = GetUserIDFromUsername($urlParts[1]); 
 

 

 

 
       function GetUserIDFromUsername($username) { 
 
        // For some reason, changing the user agent does expose the user's UID 
 
        $options = array('http' => array('user_agent' => 'some_obscure_browser')); 
 
        $context = stream_context_create($options); 
 
        $fbsite = file_get_contents('https://www.facebook.com/' . $username, false, $context); 
 

 
        // ID is exposed in some piece of JS code, so we'll just extract it 
 
        $fbIDPattern = '/\"entity_id\":\"(\d+)\"/'; 
 
        if (!preg_match($fbIDPattern, $fbsite, $matches)) { 
 
         throw new Exception('Unofficial API is broken or user not found'); 
 
        } 
 
        return $matches[1]; 
 
       } 
 

 
       echo "My Id is : "." ".$username; 
 

 
      } 
 
       
 
       
 
        
 
      
 
      }

+0

你确定你正在解析来自** URL **的确切数据吗?确定回应。 –

+0

当我尝试使用相同的代码,只是删除isset方法,然后它返回所需的数据,你可以尝试在一个简单的PHP,提供您的Facebook网址 – Nadeem

回答

1

调用前声明你的方法GetUserIDFromUsername($ params)方法。 您可以将该方法移到调用者的顶部。

+0

谢谢sooooo它对我很有用! – Nadeem

相关问题