Javascript variables to php?

T

TheJkWhoSaysNi

Guest
I have a winamp plugin called blogamp which generates what song winamp is playing and uploads it to the web via FTP.
I want to get the name of the song s.name variable in the js file and use that variable in PHP so i can create an image and use it in my signature for some forums.

How can i copy the js variable to php?

I cant use fread, fopen or anything like that because the text is generated by a javascript function and is not actualling in the html code.

Thanks for any help.
 
J

Jonty

Guest
Unfortunately this is very hard to accomplish since PHP and JavaScript are two fundamentally different languages. However, I had thought of a sneeky way of getting around all the usual barriers, but first I'd need to see the source code of the .js file which is generated, if that's okay? If the file is how I hope it is, then it might be possible to get the information we need.

Kind Regards

Jonty

P.S. Roll on .NET when all languages will be compatible ;)
 
T

TheJkWhoSaysNi

Guest
the js file:
Code:
function show(item)
{
    if (item.style.display=='none')
    {
        item.style.display='';
    }
    else
    {
        item.style.display='none'
    }        
}

function DisplaySong( s, i, title_style_aux, body_style_aux, hide_hr )
{
    var space = "";
    var style_name = "";
    var style_body = "";
    if ( title_style_aux )
    {
        style_name += title_style_aux;
    }
    if ( body_style_aux )
    {
        style_body += body_style_aux;
    }    

    document.write( s.title );

    if ( !hide_hr ) 
        document.write( "" );

}

function DisplaySongs( style1, style2, hide_hr )
{
    var n = 10; // default
    if ( blogamp_num_songs )
    {
        n = blogamp_num_songs;
    }
    for ( i = 0; i < blogamp_num_songs; i++ )
    {
        if ( musics[i] )
        {
            //DisplaySong( musics[i], i, "font-family:Arial;font-weight:bold;font-size:8pt;", "font-family:Arial;font-size:8pt;"  );
            DisplaySong( musics[i], i, style1, style2, hide_hr );
        }
    }


}

Note: this is not the original JS and is not at all tidied up, it still contails all the formatting vars which i just made blank because i wanted it to just display the song and nothing else.

the information for that js file is got from the file generated by blogamp which looks like

Code:
function song( _length, _samplerate, _bitrate, _channels, _title, _year, _month, _day, _hour, _minute, _second )
{
	this.title = _title;
	this.length = _length;
	this.samplerate = _samplerate;
	this.bitrate = _bitrate;
	this.channels = _channels;
	this.year = _year;
	this.month = _month;
	this.day = _day;
	this.hour = _hour;
	this.minute = _minute;
	this.second = _second;
}
var blogamp_num_songs = 1;
var musics=new Array();
musics[0]=new song( 200,44,128,2,"cKy - The Human Drive in Hifi",2003,1,25,12,46,3 );

Which is then used togeather with the first file like this:

Code:
<html>
<head>
<script src="mp3.js"></script>
<script src="display_playlist.js"></script>
</head>
<body>
<script>
DisplaySongs( "color: blue; text-decoration: underline;", "" );
</script>
</body>
</html>
 
J

Jonty

Guest
I'm afraid the way I was thinking of will not work :( Unfortunately, I really cannot think of a viable way around this problem. PHP and JavaScript just aren't meant to be compatible.

Some other ways people have used include: query strings (to pass information between the two, but that's not really feasible); cookies (set by one and accessed by the other, but because of the way in which the information is accessed, that's not really suitable); advanced document parsing (how I was thinking of doing it, but unfortunately it wouldn't be possible to code it).

Sorry
 
T

TheJkWhoSaysNi

Guest
Well i found a different plugin :) one that did nearly the same thing..

Now i just have to tweak the image size...

song2.php
 
J

Jonty

Guest
Good good :)

You know if you want to be fancy you can actually create an image offline, upload it, and then append the text as if it were a layer of that image. If done correctly, it can be very cool :cool:

Kind Regards
 

Users who are viewing this thread

Top Bottom