bschultz Posted April 4, 2011 Share Posted April 4, 2011 I'm trying to get a php script working to download the latest CNN news podcast each hour. CNN names the file based on the year, month, day, and time. Here's what I'm trying: <?php $year = date('Y'); $month = date('m'); $day = date('d'); $now = date('Y-m-d-h'); $hour = date('gA'); $hourplus1 = ($hour + 1); $hourminus1 = ($hour - 1); $ampm = date('A'); $url = "http://podcasts.cnn.net/cnn/services/podcasting/newscast/" . "audio/" . "$year" . "/" . "$month" . "/" . "$day" . "/CNN-News-" . "$month" . "-" . "$day" . "-" . "$year" . "-" . "$hourplus1" . "$ampm" . ".mp3"; echo $url; echo system('wget "$url"'); ?> When running from the shell, I get an "http://: invalid hostname" error. The echo of $url looks right...but it won't run from shell. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/232657-concatenate-wget-variables-in-url-using-shell/ Share on other sites More sharing options...
JonnySnip3r Posted April 4, 2011 Share Posted April 4, 2011 Hey dude! could you post a sample url from a working url Quote Link to comment https://forums.phpfreaks.com/topic/232657-concatenate-wget-variables-in-url-using-shell/#findComment-1196667 Share on other sites More sharing options...
dcro2 Posted April 4, 2011 Share Posted April 4, 2011 Here you go. I fixed up your hour calculation too and the years <?php //date_default_timezone_set('US/Eastern'); $fullyear = date('Y'); $year = date('y'); $month = date('m'); $day = date('d'); $now = date('Y-m-d-h'); $hour = date('g'); $hourplus1 = date('g', strtotime("Now +1 hour")); $hourminus1 = date('g', strtotime("Now -1 hour")); $ampm = date('A'); $url = "http://podcasts.cnn.net/cnn/services/podcasting/newscast/" . "audio/" . "$fullyear" . "/" . "$month" . "/" . "$day" . "/CNN-News-" . "$month" . "-" . "$day" . "-" . "$year" . "-" . "$hourminus1" . "$ampm" . ".mp3"; echo system('wget '.escapeshellcmd($url)); ?> Here's a shorter way of doing this: $path = date('Y/m/d/\C\N\N-\N\e\w\s-m-d-y-gA', strtotime("Now -1 hour")); $url = "http://podcasts.cnn.net/cnn/services/podcasting/newscast/" . "audio/" . $path . ".mp3"; Quote Link to comment https://forums.phpfreaks.com/topic/232657-concatenate-wget-variables-in-url-using-shell/#findComment-1196676 Share on other sites More sharing options...
bschultz Posted April 4, 2011 Author Share Posted April 4, 2011 thanks much dcro2...worked great. Quote Link to comment https://forums.phpfreaks.com/topic/232657-concatenate-wget-variables-in-url-using-shell/#findComment-1196746 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.