How to call function from within echo and pass it array value ?
HI all i am trying to pass a fuction array value from within echo statemnt but i keep getting error. I want to call the function and pass it array value and then get the returned value with in echo statement. Could any one tell me how to achive this task ?
error:
Quote:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in \xml2.php on line 69
pointing at :
PHP Code:
echo " <location>" . get_link(".$videoinfo[$i]['url'].")"</location>\n";
PHP Code:
<?
..................
$videoinfo = parse_videoinfo($xml, $fields);
//echo '<pre>' . print_r($videoinfo, true) .'</pre>';
// third, the playlist is built in an xspf format
// we'll first add an xml header and the opening tags ..
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='UTF-8' ?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <trackList>\n";
for($i=0;$i<=count($videoinfo);$i++){
echo " <track>\n";
echo " <title>" . $videoinfo[$i]['title'] . "</title>\n";
echo " <creator>By me</creator>\n";
echo " <location>" . get_link(".$videoinfo[$i]['url'].")"</location>\n";
echo " </track>\n";
}
// .. and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
function get_link($url){
if ($html = file_get_contents($url)){
if(preg_match_all("/\b(?:video_id)\b:.*/", $html, $matches)){
$ref = $matches[0][0];
//echo $ref.'<br>';
preg_match_all("/\'[^\'\\\\\r\n]*(?:\\\\.[^\'\\\\\r\n]*)*\'/", $ref, $match);
//video_id:'WAvj0iY1Zig',l:'142',t:'OEgsToPDskLspgdtd49MOElkAv_WEJmW',sk:'2ZgBZFfneV2DzW3Zb8g2AAC1
//print_r ($match);
$id1 = str_replace("'", "", $match[0][0]);
$id2 = str_replace("'", "", $match[0][2]);
$id3 = str_replace("'", "", $match[0][3]);
$id = $id1.'&t='.$id2.'&sk='.$id3;
//echo $id;
$url = 'http://youtube.com/get_video.php?video_id='.$id;
$url = get_headers($url);
//$url = print_r($url);
$url = $url[9];
//echo $id;
$url = substr($url,10);
$url = $url.'.flv';
//echo $url;
return $url;
}
return false;
}
}
?>
Re: How to call function from within echo and pass it array value ?
shouldn't there be a "." in there after the closing ) to the function?
Code:
echo " <location>" . get_link(".$videoinfo[$i]['url'].")."</location>\n";
And what's with passing the text ".$videoinfo[$i]['url']."?
Try this....
Code:
echo " <location>" . get_link($videoinfo[$i]['url'])."</location>\n";
-tg
Re: How to call function from within echo and pass it array value ?
Thnaks for your help. The value that i am passing is youtube url link and the function finds out the direct flv link which i need.
Since the script takes too much time to process i get the follwoing error. I need to call the function 100 times and construct the xml but i keep getting error. could you tell me how to over come this problem this problem?Thanks
Quote:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
The following tags were not closed: playlist, trackList, track. Error processing resource 'http://localhost/list...
<br />
<b>Fatal error</b>: Maximum execution time of 30 seconds exceeded in <b>\xml2.php</b> on line <b>94</b><br />
could you also tell me how to call same function and this time send it
mysql url value ? I tried the following but i got empty value :
PHP Code:
echo " <location>" . get_link($row["url"])."</location>\n";
There is nothing wrong with while loop since the follwing is pulling title from db:
PHP Code:
echo " <title>" . $row["title"] . "</title>\n";
PHP Code:
......
// print the random numbers
while($row = @mysql_fetch_array($result)) {
echo " <track>\n";
echo " <title>" . $row["title"] . "</title>\n";
echo " <creator>By me</creator>\n";
//echo " <location>" . $videoinfo[$i]['url'] . ".flv</location>\n";
echo " <location>" . get_link($row["url"])."</location>\n";
echo " </track>\n";
}
// .. and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
......
Re: How to call function from within echo and pass it array value ?
does it work when you comment out the location line?
-tg
Re: How to call function from within echo and pass it array value ?
Quote:
Originally Posted by techgnome
does it work when you comment out the location line?
-tg
Yes it works when i comment out the location line.
Re: How to call function from within echo and pass it array value ?
What happens when you comment out this line?
Code:
$url = get_headers($url);
-tg
Re: How to call function from within echo and pass it array value ?
Quote:
Originally Posted by techgnome
What happens when you comment out this line?
Code:
$url = get_headers($url);
-tg
i tried that and i get this in the screen :
No xml and no error!!! That function is not written by me. i found it from a website. i even tried to make the script running time to unlimited but didn't work!!
Re: How to call function from within echo and pass it array value ?
Well, I think there's two things here.... get_headers is the reason for the timeout issues you are getting.... it's taking too long to get the headers. There may also be a problem with what you are doing with that header info when you get it back.
But I'm also no expert in PHP either...
-tg