Jump to content

Testing functions


selenin

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.