selenin Posted June 1, 2010 Share Posted June 1, 2010 Hello it's me again, I'm learning functions at the moment, but have problems to test them, so that's what I have written so far: <?php function get_info($url) { $video_data = array(); preg_match('/.{13}$/i', $url, $matches); $video_id = $matches[0]; $target_url = 'http://www.novamov.com/video/'. $video_id; $error = 0; if(function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $target_url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0'); $video_data = curl_exec($ch); $errormsg = curl_error($ch); curl_close($ch); if($errormsg != '') { echo $errormsg; return false; } } else if(ini_get('allow_url_fopen') == 1) { $video_data = @file($target_url); if($video_data === false) $error = 1; } if(!is_array($video_data)) { $video_data = explode("\n", $video_data); } return $video_data; } function get_flv($video_data) { $movie_url = ''; preg_match('/file",.*/', $video_data, $matches); $split = $matches[0]; $split = explode('"', $split); $movie_url = $split[2]; return $movie_url; } $url = 'http://www.novamov.com/video/dfre8qs9n4yas'; get_info($url); print_r(get_flv($video_data)); the get_info() works fine, but how can I now give the $video_data to get_flv() to test if it's working? Link to comment https://forums.phpfreaks.com/topic/203559-testing-functions/ Share on other sites More sharing options...
premiso Posted June 1, 2010 Share Posted June 1, 2010 $video_data = get_info($url); print_r(get_flv($video_data)); Or: print_r(get_flv(get_info($url))); Either should work. Link to comment https://forums.phpfreaks.com/topic/203559-testing-functions/#findComment-1066296 Share on other sites More sharing options...
selenin Posted June 1, 2010 Author Share Posted June 1, 2010 Thanks a lot premiso damn my second function get_flv() is not working this warning : Warning: preg_match() expects parameter 2 to be string, never seen before... Link to comment https://forums.phpfreaks.com/topic/203559-testing-functions/#findComment-1066306 Share on other sites More sharing options...
Alex Posted June 1, 2010 Share Posted June 1, 2010 [tt]get_info()[/url] returns an array which is then used in your second function. You can't use preg_match() with an array. Link to comment https://forums.phpfreaks.com/topic/203559-testing-functions/#findComment-1066313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.