你如何构建youtube url?

I am wondering how the youtube url is constructed? for example https://www.youtube.com/watch?v=L7Jd910Bw84

  1. how is the value L7Jd910Bw8 created, is it a hash value ?
  2. is there any PHP function to use for creating this kind of urls?
  3. how is it possible to make sure that the two diffrent objects dont get the same value ?
  4. what is the advantages and disanvatages using this kind of url?

Thanks :) !

  1. It is basically just an ID to uniquely identify a video. Technically, there is no need to hash it, but they do encode it into a string to make the ID a little more unreadable.
  2. Not specifically for YouTube URLs, but it is easy to create your own "hashed" ID string for any resource item with a numeric ID (like an auto-increment numeric primary key). You just run the numeric ID through some simple reversible math function, then encode the resultant number with an alphabet of characters you want, e.g. base58. Or you can simply hash it with a more complicated algorithm, if CPU power is not a concern.
  3. If your IDs are different to begin with, there should be no collisions if all you do is a simple encoding, e.g. some math function, then decimal to base58. Even if you use a more complicated algorithm, there's also next-to-zero chance for most algorithms.
  4. Advantage and Disadvantage
    • Advantage: security / privacy. Since most numeric IDs run in sequence, if you simply use id=123456, everyone sort of knows that you have 123456 items in your DB. With an encoded string, nobody knows.
    • Disadvantage: processing. Obviously, there's going to be a slight increase in processing required to generate these IDs.