PHPackages                             andreinocenti/php-social-media-url-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. andreinocenti/php-social-media-url-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

andreinocenti/php-social-media-url-validator
============================================

PHP library for validating generic URLs and specific social media URLs, with ID extraction.

v1.0.11(9mo ago)1411MITPHP

Since Jul 15Pushed 9mo agoCompare

[ Source](https://github.com/andreinocenti/php-social-media-url-validator)[ Packagist](https://packagist.org/packages/andreinocenti/php-social-media-url-validator)[ RSS](/packages/andreinocenti-php-social-media-url-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (13)Used By (1)

Social Media URL Validator
==========================

[](#social-media-url-validator)

**Social Media URL Validator** is a lightweight PHP library for validating, parsing, and inspecting URLs—both generic and platform-specific (Instagram, Facebook, TikTok, LinkedIn, YouTube, Twitter). It provides:

- **Generic URL validation and detection**
- **Specific Social Media URL validation and detection**
- **Social Media URL Category validation and detection**

---

Features
--------

[](#features)

- **URL syntax validation**
- **Platform-specific validation** and **ID extraction**
    - Instagram posts and profiles
    - Facebook posts and pages
    - TikTok videos and profiles
    - LinkedIn posts and profiles
    - YouTube channels, videos, and custom URLs
    - Twitter/X tweets and profiles

---

Installation
------------

[](#installation)

Require the package via Composer:

```
composer require andreinocenti/php-social-media-url-validator
```

---

Validator Basic Usage
---------------------

[](#validator-basic-usage)

```
use AndreInocenti\SocialUrlValidator\UrlValidator;

$validator = new UrlValidator();

// is Instagram URL detect
echo $validator->isInstagram('https://www.instagram.com/p/POSTID/'));
Output: "instagram"

// Generic social media URL detect
echo $validator->detect('https://www.instagram.com/p/POSTID/'));
Output: "instagram"

// // Instagram post URL check
// $url = 'https://www.instagram.com/p/POSTID/';
// if ($validator->isInstagramUrl($url)) {
//     $postId = $validator->extractInstagramId($url);
//     echo "Instagram Post ID: $postId";
// }
```

---

URL Category Detection Basic Usage
----------------------------------

[](#url-category-detection-basic-usage)

Beyond simply checking if a URL belongs to a given platform, you can also **detect the specific resource type** (e.g. profile, post, video, reel) using the `detectUrlCategory()` method:

```
use AndreInocenti\SocialMediaUrlValidator\UrlValidator;

$validator = new UrlValidator;

$url = 'https://www.instagram.com/p/POSTID/';
if ($validator->isInstagram($url)) {
    echo $validator->instagramCategory($url);
    output: 'post'
}

$url = 'https://x.com/X/status/1942652662987776268';
$validator->detectSocialMediaCategory($url);
output: 'post'
```

---

Social URL Validator Functions
------------------------------

[](#social-url-validator-functions)

The functions below allow you to validate or detect URLs for various social media platforms. Each function returns `true` if the URL is valid for that platform, or `false` otherwise. Additionally the `detect()` function returns the name of the social media platform if the URL is valid, or `null` if it is not recognized.

FunctionDescription`isInstagram(string $url)`Returns `true` if the URL is a valid Instagram profile/post/…`isTwitter(string $url)`Returns `true` if the URL is a valid Twitter/X profile/tweet`isFacebook(string $url)`Returns `true` if the URL is a valid Facebook profile/page/post`isLinkedIn(string $url)`Returns `true` if the URL is a valid LinkedIn profile/company/post`isTikTok(string $url)`Returns `true` if the URL is a valid TikTok profile/video`isYouTube(string $url)`Returns `true` if the URL is a valid YouTube channel/video/shorts`detectSocialMedia(string $url)`Returns a string with the name of the Social Media for a generic Social Media URL, or `null` if not recognized---

Social Media URL Category Detector
----------------------------------

[](#social-media-url-category-detector)

FunctionDescription`instagramCategory(string $url)`Returns the resource category for an Instagram URL (`profile`, `post`, `reel`, `igtv`, or `null`)`twitterCategory(string $url)`Returns the resource category for a Twitter/X URL (`profile`, `tweet`, or `null`)`facebookCategory(string $url)`Returns the resource category for a Facebook URL (`profile`, `page`, `post`, or `null`)`linkedInCategory(string $url)`Returns the resource category for a LinkedIn URL (`profile`, `company`, `post`, or `null`)`tiktokCategory(string $url)`Returns the resource category for a TikTok URL (`profile`, `video`, or `null`)`youTubeCategory(string $url)`Returns the resource category for a YouTube URL (`channel`, `user`, `custom`, `video`, `shorts`, or `null`)`detectSocialMediaCategory(string $url)`Returns the resource category for a generic Social Media URL, or `null` if not recognized---

### URL Category Detection - Supported Platforms &amp; Categories

[](#url-category-detection---supported-platforms--categories)

PlatformCategoryExample URL**Instagram**`profile``https://instagram.com/username/``post``https://instagram.com/p/POSTID/``reel``https://instagram.com/reel/REELID/``igtv``https://instagram.com/tv/VIDEOID/`**Twitter/X**`profile``https://twitter.com/username``post``https://twitter.com/username/status/TWEETID`**Facebook**`profile``https://facebook.com/profile.php?id=1234``page``https://facebook.com/PageName``post``https://facebook.com/PageName/posts/POSTID`**LinkedIn**`profile``https://linkedin.com/in/username``company``https://linkedin.com/company/companyName``post``https://linkedin.com/feed/update/urn:li:activity:ACTID`**TikTok**`profile``https://www.tiktok.com/@username``video``https://www.tiktok.com/@username/video/VIDEOID`**YouTube**`channel``https://www.youtube.com/channel/CHANNELID``user``https://www.youtube.com/user/USERNAME``custom``https://www.youtube.com/c/CUSTOMNAME``video``https://www.youtube.com/watch?v=VIDEOID``shorts``https://www.youtube.com/shorts/SHORTID`Contributing
------------

[](#contributing)

Contributions are welcome! Please open issues or pull requests on the GitHub repository.

---

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance58

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

12

Last Release

272d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d5b3ad27cc2ab495bd40b9837f085b35efd442cbd88ceac5971f273ecdd88a6?d=identicon)[andreinocenti](/maintainers/andreinocenti)

---

Top Contributors

[![andreinocenti](https://avatars.githubusercontent.com/u/39701679?v=4)](https://github.com/andreinocenti "andreinocenti (41 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/andreinocenti-php-social-media-url-validator/health.svg)

```
[![Health](https://phpackages.com/badges/andreinocenti-php-social-media-url-validator/health.svg)](https://phpackages.com/packages/andreinocenti-php-social-media-url-validator)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
