There is a certain array which gets from base.

$a = 'текст https://www.youtube.com/watch?v=2B-nbLVqDjY еще текст {smiles} '; 

We need a function that will look for the YouTube link in the array, take the identifier and replace the link with

 <iframe width="560" height="315" src="https://www.youtube.com/embed/2B-nbLVqDjY" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> 

rummaged a floor of Google, found nothing sensible. help)

  • If you find the answer to your question, please tick it with a green check mark under the arrows for voting. - user218976
  • one
    @Anamnian, writes that it is possible only after 2 days. - Alexander

1 answer 1

He asked, he wrote)) use on health :)

 function video($str) { $str = preg_replace('#(^|\s|\(|\])((https?://)?www\.youtube\.com/watch\?(.*?&)*v=([^ \r\n\t`\'"<]+))(,|\[|<|\s|$)#iuU', '\1<iframe src="http://www.youtube.com/embed/\5?rel=0" frameborder="0" allowfullscreen="allowfullscreen"></iframe>\6', $str); return $str; } 
  • one
    You can mark your own answer as a solution (a green check mark), so as not to leave the question open (well, and get a rating at the same time) - Anatoly Shevelev