Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:43:56+00:00 2026-06-12T03:43:56+00:00

I am trying to get the facebook username or id from a facebook url

  • 0

I am trying to get the facebook username or id from a facebook url and was wondering if you could help me. I’m sure it’s just a simple regex function but I have tried and can’t seem to do it myself.

Here’s what I’ve been trying to get from the url.

http://www.facebook.com/myusername/

or the numerical id

http://www.facebook.com/2285652/

I would be very grateful if anyone could help me achieve this via PHP

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:43:57+00:00Added an answer on June 12, 2026 at 3:43 am
    preg_match('#https?\://(?:www\.)?facebook\.com/(\d+|[A-Za-z0-9\.]+)/?#',$str,$matches);
    

    The pattern is versatile so it matches:

    1. http and https URL’s.
    2. URL’s with or without the www prefix.
    3. URL’s with or without the trailing /.
    4. Matches Facebook numerical ID’s.
    5. Matches Facebook’s rules for usernames.

    Usernames can only contain alphanumeric characters (A-Z, 0-9) or a
    period (“.”).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'am trying to get the Login button from Facebook to work on my website
I'm trying to get a long value from a String containing a Facebook ID,
I'm trying to get the education info from Facebook's graph API using stdclass. here's
I am using cakephp. I am trying get data from facebook using file_get_contents. I
Im trying to get the Facebook users id saved in my database but I
I'm currently trying to get a Facebook App up and running. But I get
I am trying to get all facebook posts from a facebook group in ASP.NET
I'm trying to get the domain of a given URL. For example http://www.facebook.com/someuser/ will
I'm trying to get Facebook Connect functionality working in my iPhone app. I'm wondering
I am trying to get the facebook page IDs from: http://fanpagelist.com/category/top_users/view/list/sort/fans/page1 There's ~25 of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.