Vb.net programmer moving to PHP (Need help making a script)
Posted: Thu Mar 03, 2011 1:22 pm
Hey there! I'm new here as you can see 
I'm 17 and from the UK.
I've been programming in VB.net for almost a year now and am pretty comfortable with it
I have now decided to move forward and code with PHP and Javascript and thought I would join this forum and ask for a bit of help from you masters,if any of you people would be kind enough to provide it that is
So far from spending the last week browsing through random scripts found on the internet, I have learned quite a bit.
So far I have learned:
- That each line of code (well some exclusions,not every line), needs to have a semi colon at the end of it ";"
- Variables can be of ANY datatype in PHP (even an array) - just by typing "$variable_boolean = true;" - so theres no need to declare the variable as a datatype.
- PHP can be used in many ways, mixed in html of course, or with databases etc.
- THAT I NEED TO ACTUALLY REMEMBER THE NAME OF SOME FUNCTIONS IF I WANT TO START CODING WITH PHP.
Anyway, on to the coding part of this topic. So far I have created this (I know its mainly JS code right now, but ah well lol)
What I want to do is read an xml file and show it to the user in a friendly format. Here's my code:
My XML (playlist) structure:
As you can see i am getting a parameter after the url and displaying a filename using this method, is this safe ?
And how could I make the script more advanced to show a message if no url is passed to the php file ?
Thanks for reading, and I hope you can help
I'm 17 and from the UK.
I've been programming in VB.net for almost a year now and am pretty comfortable with it
I have now decided to move forward and code with PHP and Javascript and thought I would join this forum and ask for a bit of help from you masters,if any of you people would be kind enough to provide it that is
So far from spending the last week browsing through random scripts found on the internet, I have learned quite a bit.
So far I have learned:
- That each line of code (well some exclusions,not every line), needs to have a semi colon at the end of it ";"
- Variables can be of ANY datatype in PHP (even an array) - just by typing "$variable_boolean = true;" - so theres no need to declare the variable as a datatype.
- PHP can be used in many ways, mixed in html of course, or with databases etc.
- THAT I NEED TO ACTUALLY REMEMBER THE NAME OF SOME FUNCTIONS IF I WANT TO START CODING WITH PHP.
Anyway, on to the coding part of this topic. So far I have created this (I know its mainly JS code right now, but ah well lol)
What I want to do is read an xml file and show it to the user in a friendly format. Here's my code:
Code: Select all
<?
$playlisturl = $_GET['playlist'];
?>
<html>
<head>
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "<?= $playlisturl ?>",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
x=xmlDoc.getElementsByTagName("song");
function displayCDInfo(i)
{
songname=(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
songid=(x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue);
genre=(x[i].getElementsByTagName("genre")[0].childNodes[0].nodeValue);
txt='<img src="tune.jpg" alt="Image" border="0">'+" Song Name: "+songname+'<br /> <img src="tune.jpg" alt="Image" border="0">'+" Song ID: "+songid+'<br /> <img src="tune.jpg" alt="Image" border="0">'+" Song genre: "+genre+'<br /> <img src="http://img.youtube.com/vi/' +songid+ '/0.jpg" alt="Image" border="0">' ;
document.getElementById("songinfo").innerHTML=txt;
}
</script>
</head>
<body>
<div id='songinfo'>Click on a Song to view more information about it...</div><br />
<script type="text/javascript">
document.write("<table border='1'>");
for (var i=0;i<x.length;i++)
{
document.write("<tr onclick='displayCDInfo(" + i + ")'>");
document.write("<td>");
document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>
</html>Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<!--Tune Nanny Playlist - test playlist-->
<playlist>
<info>
<playlistname>test playlist</playlistname>
<created>01/03/2011 18:51:01</created>
</info>
<song>
<name>Alien Ant Farm - Smooth Criminal</name>
<id>CDl9ZMfj6aE</id>
<genre>0</genre>
</song>
<song>
<name>Cream - Sunshine Of Your Love</name>
<id>Cqh54rSzheg</id>
<genre>0</genre>
</song>
<song>
<name>Tom Jones - Mama Told Me Not To Come</name>
<id>vpsu0n64bpQ</id>
<genre>0</genre>
</song>
</playlist>And how could I make the script more advanced to show a message if no url is passed to the php file ?
Thanks for reading, and I hope you can help