I’m trying to grab parts of a URL to create an embed code. I have the following URL structure:
http://www.mtv.com/videos/foster-the-people/761507/houdini.jhtml#id=1518072&vid=761507
I need to use preg_match to break the URL into a few pieces. Ideally, I want to test for the structure of the URL and get the numeric values from the URL. Ultimately, I would like an array in the following form after the preg_match:
Array (
0 => 761507
1 => 1518072
2 => 761507
)
Note that “foster-the-people” and “houdini” are dynamic elements that can contain letters, numbers and “-” and will change from URL to URL.
Thanks for the help!
Try this : (UPDATED)
Demo :
http://regexr.com?30qo4
Code :
Output :
Hint : The elements you need are
$matches[1],$matches[2]and$matches[3]