0

I'm still very new to PHP so sorry if this seems simple to some people.

So I have a PHP Script that I would like to run, however when I run the script the variable in the script doesn't get executed. I'm using php's exec function.

<?php

$url = $_POST['url'];

echo exec('youtube-dl \--extract-audio \--audio-format \mp3 \$url 2>&1', $output);
print_r($output);

?>

Everything seems to work, however the $url variable never gets inserted and the script returns with the error "We could not find a video by the URL of $url"

Now if I type "echo $url;" it echos the url like normal.

Any ideas as to why this wouldn't work in the exec command? All help would be greatly appreciated!! Thanks in advance!!!

Tarik
  • 4,961
  • 3
  • 36
  • 67
  • 1
    `"youtube-dl \--extract-audio \--audio-format \mp3 \$url 2>&1"` try that. Variables don't get parsed in single quotes. – Funk Forty Niner Feb 15 '15 at 04:21
  • also, see http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – Tivie Feb 15 '15 at 04:24

1 Answers1

0

I found the answer thanks to Fred -ii- in the comments. I found out variables don't get parsed in single quotes ( ' ' ).

Instead I had to use double quotes ( " " ).

Thank you guys again so much for the help!

  • Great and you're welcome, however answers usually come from the person who provided the answer ;-) where you get to accept it after. – Funk Forty Niner Feb 15 '15 at 16:12