title: How to Get Numeric ID from Facebook Profile or Page URL? PHP ,Facebook Graph API
body: <p>Hello super awesome people from stackoverflow!</p>
  
  <p>I need help with this php script.. I want to get facebook id from user when it enters his facebook profile link in the input box. example of the profile link: <a href="https://www.facebook.com/profilename" rel="nofollow">https://www.facebook.com/profilename</a>. I have a script that collect the "profilename"from the url and save it to the $username but now i need the script to convert that profilename to the facebook ID of that profile and save it to the $username. Now i know you can get facebook id manually easy when you right click on the user Profile Picture than click on Copy link adress and the last number after .(dot) is user profile ID..Or another method is to scan the page for <code>&lt;meta property="al:ios:url"</code> or <code>&lt;meta property="al:android:url"</code> That will also get user ID. And this is the site that has that working script. <a href="http://findmyfbid.com/" rel="nofollow">http://findmyfbid.com/</a></p>
  
  <p>This is my code now: As you can see it only takes last part of the url.. Please help to make it right to convert that profilename to ID and save it to $username .Thank you.</p>
  
  <pre><code> /* CHECKING */
          if (isset($_POST["urlCheck"])) {
              $url = $_POST["urlCheck"];
              $urlParts = explode("facebook.com/", $url);
              $username = GetOnlyUsername($urlParts[1]);
  
              if (filter_var($url, FILTER_VALIDATE_URL) !== false) 
                  exit("success");
              else 
                  exit("error");              
          }
  
          /* TAKING INFO */
          if (isset($_POST["urlGetData"])) {
              $url = $_POST["urlGetData"];
              $urlParts = explode("facebook.com/", $url);
              $username = GetOnlyUsername($urlParts[1]);
  
              $name= GetData($username);
  
  
      function GetOnlyUsername($username) {
          if ((strpos($username, 'profile.php?id=')) !== false) {
              $username = str_replace("profile.php?id=", "", $username);  
              if ((strpos($username, '&amp;fref=ts')) !== false) {
                  $username = str_replace("&amp;fref=ts", "", $username); 
              }
          } else if ((strpos($username, '?')) !== false) {
              $test = explode("?", $username);
              $username = $test[0];   
          }
          return $username;
      }
  </code></pre>