Use strpos()
to find the watch?v=
, then use the substr()
method to get 11 characters after.
docs for the strpos
function:
http://us2.php.net/strpos
docs for the substr
function:
http://www.php.net/manual/en/function.substr.php
Question
I want to be able to only store the 11 characters following a certain keyword (watch?v=) in PHP, nothing after and nothing before. How do I achieve this?
Solution
Use strpos()
to find the watch?v=
, then use the substr()
method to get 11 characters after.
docs for the strpos
function:
http://us2.php.net/strpos
docs for the substr
function:
http://www.php.net/manual/en/function.substr.php
OTHER TIPS
You can do it with PHP strpos() and substr() functions.
echo substr($string, strpos($string, "keyword"), length);
In here,
$string - url,
"keyword" - watch?v=,
$length - 11