I want extract from the text youtube url string like https://www.youtube.com/watch?time_continue=218&v=0EB7zh_7UE4
and the video id like 0EB7zh_7UE4
so I can inject text behind the string based on video id. This is my sample text:
This is an example page will show up https://www.youtube.com/watch?time_continue=218&v=0EB7zh_7UE4 Bike https://www.youtube.com/watch?v=0EB7zh_7UE4&feature=youtu.be&app=desktop messenger by day, aspiring actor by night, and this is my website. I live in https://youtu.be/1EB7zh_7UE4 Los Angeles, have a great dog named Jack, and I https://www.youtube.com/watch?v=0EB7zh_7UE4&feature=youtu.be like piña coladasdoohickeys https://www.youtube.com/watch?v=4EB7zh_7UE4 you should go to <a href="http://example.com/wp-admin/">your dashboard</a> to delete this page and create new pages for your content. Have fun!
https://www.youtube.com/watch?v=0EB7zh_7UE4
more
https://www.youtube.com/watch?v=2EB7zh_7UE4&feature=youtu.be
That\'s all..
This is regex I got so far but errors are as follows:
it adds
(here)
string before end of link string (in the middle). I want to add(here)
at the end you Youtube url link stringit returns multiple
here
injection
See code:
function regex($sample_text) {
if (preg_match_all('#(?:https?:\/\/)?(?:m\.|www\.)?(?:youtu\.be\/|youtube\-nocookie\.com\/embed\/|youtube\.com\/(?:embed\/|v\/|e\/|\?v=|shared\?ci=|watch\?v=|watch\?.+&v=))([-_A-Za-z0-9]{10}[AEIMQUYcgkosw048])(.*?)\b#s', $sample_text, $matches, PREG_SET_ORDER)) {
print_r($matches);
foreach ($matches as $match) {
$add = ' (here)';
$processed_text = str_replace($match[0], $match[0] . $add, $sample_text);
}
}
return $processed_text;
}
echo regex($sample_test);
Where I do mistake?
Note: question + sample text have been updated.