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?

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top