Answer the question
In order to leave comments, you need to log in
How to check for a variable?
Hello.
There is this code:
<?php
$videolink = $modx->resource->getTVValue('12');
$itemArray = explode(' ', $videolink);
foreach ($itemArray as $item){
$ytarray=explode("/", $item);
$ytendstring=end($ytarray);
$ytendarray=explode("?v=", $ytendstring);
$ytendstring=end($ytendarray);
$ytendarray=explode("&", $ytendstring);
$ytendarray=explode(",", $ytendstring);
$ytcode=$ytendarray[0];
echo "
<h2>Видео</h2>
<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/$ytcode\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>
";
}
<h2>Видео</h2>
<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/$ytcode\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>
Answer the question
In order to leave comments, you need to log in
if(!is_null($ytcode)){
echo "
<h2>Видео</h2>
<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/$ytcode\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>
";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question