I need a 1 liner RegEx to get the ID from a url. I am using this but it does not return the id. Any idea? for the following it should return 1396. The RegEx I tried are below and none of them worked.
/(?<=id=)[^&]+/`
and (?<=ID=)\w+(?=,)
I need a 1 liner RegEx to get the ID from a url. I am using this but it does not return the id. Any idea? for the following it should return 1396. The RegEx I tried are below and none of them worked.
/(?<=id=)[^&]+/`
and (?<=ID=)\w+(?=,)
Use parse_url() and parse_str().
exmple get Id from youtube url
<?php
$url = "http://www.youtube.com/watch?v=C4kxS1ksqtw&feature=relate";
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
echo $my_array_of_vars['v'];
// Output: C4kxS1ksqtw
?>
If ID is always numeric:
/\WID=(\d+)/
This matches a non word character then ID= then captures all the following digits.