aidangig Posted September 21, 2017 Share Posted September 21, 2017 (edited) Hey, I want to use $_SERVER['REQUEST_URI'] in my addChild since I have a lot of get variables I also need to add to the 'url' node. when I use : $entry->addChild('url', 'http://boston.lit.life' . $_SERVER['REQUEST_URI']); It just duplicates this code as the 'url' : $entry->addChild('title', chop($_GET['city'] .' - '. $_GET['title']) .' for '. $_GET['price'] .' from @'. $dir_auth1); as the 'URL' node or the added child. Inside of the .xml file it adds this : <link><title>South Boston - The good stuff for $15 from @aidan</title><url/></link><link><title>South Boston - The good stuff for $15 from @aidan</title><url/></link> I want to use $_SERVER['REQUEST_URI'] for 'url' to add the entire URL INCLUDING $_GET variables inside of the xml file it is writing to. Not just duplicate the title instead. <?php $headers = 'links.xml'; $xml = simplexml_load_file('/home/thecookie12/public_html/links.xml'); $entry = $xml->addChild('link'); $entry->addChild('title', chop($_GET['city'] .' - '. $_GET['title']) .' for '. $_GET['price'] .' from @'. $dir_auth1); $entry->addChild('url', 'http://boston.lit.life' . $_SERVER['REQUEST_URI']); $xml->asXML('/home/thecookie12/public_html/links.xml') ?> If anyone has an idea of why this is not working or there is a work around please let me know. Edited September 21, 2017 by aidangig Quote Link to comment https://forums.phpfreaks.com/topic/305071-simplexml-addchild-wont-accept-_serverrequest_uri/ Share on other sites More sharing options...
ginerjm Posted September 21, 2017 Share Posted September 21, 2017 What does not working mean? Have you echo'ed out the resulting string you create with this logic? Is using $_GET your best option for this exercise? Quote Link to comment https://forums.phpfreaks.com/topic/305071-simplexml-addchild-wont-accept-_serverrequest_uri/#findComment-1551712 Share on other sites More sharing options...
aidangig Posted September 21, 2017 Author Share Posted September 21, 2017 (edited) Thank you for the quick response! I said not working because it doesn't add the entire URL with get parameters. URL without get parameters inside of the child 'url' will not function properly with what I am trying to do. Yes, currently $_GET is my best method. I believe more so that it is the $_SERVER['REQUEST_URI'] is the main issue. I tried using the strval() function It does a very basic function to convert to string. I tried using that as well. Nothing is really working as of now. Edited September 21, 2017 by aidangig Quote Link to comment https://forums.phpfreaks.com/topic/305071-simplexml-addchild-wont-accept-_serverrequest_uri/#findComment-1551715 Share on other sites More sharing options...
Solution requinix Posted September 21, 2017 Solution Share Posted September 21, 2017 addChild has an annoying quirk where you have to encode ampersands. Just ampersands. It issues a warning, and if you're not seeing it then you don't have your environment properly set up for development. As an alternative you can not specify the value in the method call and instead assign it manually. $entry->addChild('title')->value = chop($_GET['city'] .' - '. $_GET['title']) .' for '. $_GET['price'] .' from @'. $dir_auth1); Quote Link to comment https://forums.phpfreaks.com/topic/305071-simplexml-addchild-wont-accept-_serverrequest_uri/#findComment-1551718 Share on other sites More sharing options...
aidangig Posted September 21, 2017 Author Share Posted September 21, 2017 Thank you requinix! This was perfect as it set on the right foot. I wrote my own code by this definitely helped me Quote Link to comment https://forums.phpfreaks.com/topic/305071-simplexml-addchild-wont-accept-_serverrequest_uri/#findComment-1551726 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.