RandomClown Posted November 12, 2009 Share Posted November 12, 2009 Hai!Sorry if this is a noob question [i am a noob]. I am new to PHP & XML.I was trying to echo the value of an XML child, but could not get it to work completely.This is a sample of my XML document: <Stuff> <Sec> <Program>abc 123</Program> </Sec></Stuff> This is a sample of code I tried: $Section="Sec"; $Page="Program";echo $xml->$Section->Program; // Works for some reason.echo $xml->$Section->$Page; // With a 2nd variable, wont work. Does anyone know what I did wrong?Thanks for reading. Link to comment Share on other sites More sharing options...
jeffman Posted November 12, 2009 Share Posted November 12, 2009 I've worked with simpleXML but never needed to do this exact thing, so I tried it. First with one of my files, then with your exact data and code. The thing you want to do worked every time.The only answers I come up with are (1) the snippet you posted is not the code you're actually using (2) you're experiencing some sort of cache problems (3) your version of PHP is not the same as mine and for some reason that makes a difference in this context. I'm not enough of an expert in this module to know its history. FWIW, I'm on 5.2.10 Link to comment Share on other sites More sharing options...
RandomClown Posted November 13, 2009 Author Share Posted November 13, 2009 Hai! Thanks for the response.I have my project hosted on SourceForge.http://horc.sourceforge.net/It seems to work completely for some reason.I think your right about the cache problem.My new problem is getting javascript to work.. Link to comment Share on other sites More sharing options...
RandomClown Posted November 13, 2009 Author Share Posted November 13, 2009 OMG I Spent an entire 2 days on this!!!!!!!!!!!!!The reason it was working half way was because I cant /GET & in javascript.var S is the section while P was the page. I could pass S, but not P: open("GET","page.php?s=bla&p=bla",true) // & symbol exploded to & which = fail to pass multi vars. open("GET","page.php?s=bla&p=bla",true) // plain & symbol which XHTML hates. now I am trying to make my page completely [XHTML 1.1] compatible [cause I want to ]but the problem with this is I cannot use & in urls.Does anyone know of a way to send URLs?I saw POST as an alternative, but I dont want a form in my page. Link to comment Share on other sites More sharing options...
Synook Posted November 13, 2009 Share Posted November 13, 2009 XHTML "hates" the ampersand character because it has a reserved meaning, namely to begin an entity. That is why you have to turn it into an entity itself when you want to use it. However, in JS "&" has no special meaning and can be used freely.If you need to use an ampersand in XML or SGML, just use its entity. Link to comment Share on other sites More sharing options...
boen_robot Posted November 13, 2009 Share Posted November 13, 2009 The best you can do is isolate the JavaScript in its own file. It will be easiest and least painful thing to do. You won't have to do any kind of escaping with this approach.If you want to embed the JavaScript on the page, you'll have to combine several kinds of comments into one another for the sake of different parser types. Namely, you'll have to enclose your code like this: <script type="text/javascript">/*<![CDATA[*/...open("GET","page.php?s=bla&p=bla",true).../*]]>*/</script> Link to comment Share on other sites More sharing options...
RandomClown Posted November 17, 2009 Author Share Posted November 17, 2009 LOLThat seems unnecessarily difficult to embed a simple & into the URL.I will stick to embeds, thanks [didnt think of that] Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.