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

  • SEARCH
  • Home
  • 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 6119609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:34:23+00:00 2026-05-23T15:34:23+00:00

How can I write a function to check whether the provided URLs is youtube

  • 0

How can I write a function to check whether the provided URLs is youtube or vimeo?

For instance, I have this two URLs that I store in a database as strings,

http://vimeo.com/24456787


If the URL is youtube then I will rewrite the URL to,

http://www.youtube.com/embed/rj18UQjPpGA?rel=0&wmode=transparent

If the URL is vimeo then I will rewrite this URL to,

http://vimeo.com/moogaloop.swf?clip_id=24456787

Thanks.

  • 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-05-23T15:34:24+00:00Added an answer on May 23, 2026 at 3:34 pm

    As others have noted in the comments, this is a quick and dirty solution that does not handle edge cases well. If the url contains "youtube"(example.com/youtube) it will return a false positive. The parse_url() solution mentioned below is a much more robust solution.

    Regular expressions work well for this type of thing, but often strpos or substr are faster performance wise. Check out the PHP documentation for preg_match(). Below the examples there is a note for exactly this thing.

    Here is prototype code:

    function videoType($url) {
        if (strpos($url, 'youtube') > 0) {
            return 'youtube';
        } elseif (strpos($url, 'vimeo') > 0) {
            return 'vimeo';
        } else {
            return 'unknown';
        }
    }
    

    Obviously returning a string isn’t the best idea, but you get the point. Substitute your own business logic.

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

Sidebar

Related Questions

How can I write a function that accepts a variable number of arguments? Is
So I know I can write my own HTML-encoding function like this: function getHTMLEncode(t)
How can I write a wrapper that can wrap any function and can be
How do I write a function that can accept unlimited number of parameters? What
Building on another SO question , how can one check whether two well-formed XML
I have written a function, which has to check whether a username has been
I want to parse the strings, so that to check whether they have specified
How can I write a function which will return pi (π) to a given
In C++, on Linux, how can I write a function to return a temporary
How can I write a C++ function returning true if a real number is

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.