Jump to content

SimpleXML addChild won't accept $_SERVER['REQUEST_URI']


Go to solution Solved by requinix,

Recommended Posts

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 by aidangig

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 by aidangig
  • Solution

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);
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.