So, I’m looking to code in PHP a function, getType(). This function will take a user inputed string from a web form (in CodeIgniter) and then from there analyze it’s content and then determine if the string is a photo (ending in .jpg, .png, etc), a youtube video link, a vimeo video link, or just text.
I’m just having a hard time trying to visualize the best, most economical way to do this.
if (strpos($content, ".jpg|.png|.bmp"))
{ return "image"; }
else if (strpos($content, "youtube.com"))
{ return "youtube"; }
else if (strpos($content, "vimeo.com"))
{ return "vimeo" }
else
{ return "text" }
This should work:
Demo: http://codepad.viper-7.com/1V4joK
Note that there is no guarantee that it is a youtube or vimeo link. Because this only checks whether the string matches the service and nothing more.