2016-06-22 7 views
0

Ich habe ein Problem mit dem Einfügen des zuvor definierten PHP-Wertes $ video_url als eines der Array-Mitglieder. Hier der Code:PHP-Wert als Array-Member einfügen?

$video_url= "[[+virtual_tour]]"; /* [[+virtual_tour]] is MODX placeholder which contains first video url */ 

echo $video_url; /* for test reasons. Outputs https://youtu.be/9bZkp7q19f0 */ 

$url = array(
'$video_url', /* URL of the first video */ 
'https://www.youtube.com/watch?v=e-ORhEE9VVg' /*URL of the second video */ 
); 
// Extracts the YouTube ID from various URL structures 
foreach ($url as $value) { 
    if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $value, $match)) { 
     $id = $match[1]; 
echo $id; /* outputs only ID of second video, but not first */ 
    } 
} 

So habe ich etwas Wort durch Einfügen von $ video_url in Array. Vielen Dank.

Antwort

2

Versuchen ohne Anführungszeichen $video_url:

$url = array(
    $video_url, /*URL of the first video**/ 
    'https://www.youtube.com/watch?v=e-ORhEE9VVg' /* URL of the second video */ 
); 

Apostrophe do not interpolate Strings, wird der Wert von $url[0] Bedeutung ist buchstäblich $video_url.

Auch, seien Sie vorsichtig mit Kommentaren, in PHP sind sie nicht #.

+0

Versucht ohne Anführungszeichen, das gleiche Ergebnis – MyMadWeb

+0

Sind Sie Ihre Kommentare zu beheben? Entferne '#' und füge '//' hinzu. Kannst du 'var_dump ($ url)' wissen, was drin ist? –

+0

Ich habe Kommentare (und in meinem ursprünglichen Post) behoben. Hier ist var_dump ($ url) Ergebnis: array (2) { [0] => string (17) "https://youtu.be/9bZkp7q19f0" [1] => string (43) "https://www.youtube.com/watch?v=e-ORhEE9VVg" } – MyMadWeb

Verwandte Themen