...

View Full Version : Editing the string that is passed to two different xml files



Rabel
01-04-2012, 03:47 PM
Hi Guys,
I am taking a form and updating two xml files with the information, but I need to slightly alter the info.
I need to add a piece of the url to the output.
I need to add this url to the beginning on the content info on the second xml file
http://mediasrv3.blahblah.net/arch/

I have tried a bunch of different codes but it just hasn't worked,
$media2->setAttribute('url', "http://mediasrv3.blahblah.net/arch/" + $_POST['content']);
or
$media2->createTextNode('http://mediasrv3.blahblah.net/arch/'+ $_POST['content'])

The input data in the form comes in and looks like this
videos/hd/2185/36kil1vntk5uvq4auh1p4z7jbsl6e530.mp4

in the file
loadAndEdit.xml
the data that is being added should stay the same
videos/hd/2185/36kil1vntk5uvq4auh1p4z7jbsl6e530.mp4

in the file
loadAndEdit-html.xml
the data should add
http://mediasrv3.blahblah.net/arch/
to the beginning of the output, so it would equal
http://mediasrv3.blahblah.net/arch/vide ... l6e530.mp4

Thanks for the help.
Randy




/*if form to add an element has been submitted we write new item to the file*/
if (isset($_POST['submitAdd'])) {
$xml_fname = "loadAndEdit.xml";
$xml = new DOMDocument();
$xml->load($xml_fname);
$root = $xml->documentElement;

$xml2_fname = "loadAndEdit-html.xml";
$xml2 = new DOMDocument();
$xml2->load($xml2_fname);
$root2 = $xml2->documentElement;

$xpath = new DOMXPath($xml);
$xpath->registerNamespace('c', 'http://search.yahoo.com/mrss/');

$xpath2 = new DOMXPath($xml2);
$xpath2->registerNamespace('c', 'http://search.yahoo.com/mrss/');

$channel = $xpath->query("//channel");
$item = $xml->createElement('item');
$channel->item(0)->appendChild($item);
$elTitle = $xml->createElement('title');
$item->appendChild($elTitle);
$elTitle->appendChild($xml->createTextNode($_POST['itemtitle']));
$media = $xml->createElement('media:credit');
$item->appendChild($media);
$media->setAttribute('role', 'author');
$media->appendChild($xml->CreateTextNode($_POST['credit']));
$media = $xml->createElement('media:content');
$item->appendChild($media);
$media->setAttribute('url', $_POST['content']);
$media = $xml->createElement('media:thumbnail');
$item->appendChild($media);
$media->setAttribute('url', $_POST['thumbnail']);
$elprov = $xml->createElement('jwplayer:provider');
$item->appendChild($elprov);
$elprov->appendChild($xml->createTextNode('rtmp'));
$elstream = $xml->createElement('jwplayer:streamer');
$item->appendChild($elstream);
$elstream->appendChild($xml->createTextNode('rtmp://mediasrv3.praizevision.net/aecarch'));
$xml->formatOutput = true;
$xml->save($xml_fname);

$channel2 = $xpath2->query("//channel");
$item2 = $xml2->createElement('item');
$channel2->item(0)->appendChild($item2);
$elTitle2 = $xml2->createElement('title');
$item2->appendChild($elTitle2);
$elTitle2->appendChild($xml2->createTextNode($_POST['itemtitle']));
$media2 = $xml2->createElement('media:credit');
$item2->appendChild($media2);
$media2->setAttribute('role', 'author');
$media2->appendChild($xml2->CreateTextNode($_POST['credit']));
$media2 = $xml2->createElement('media:content');
$item2->appendChild($media2);
$media2->setAttribute('url', $_POST['content']);
$media2 = $xml2->createElement('media:thumbnail');
$item2->appendChild($media2);
$media2->setAttribute('url', $_POST['thumbnail']);

$xml2->formatOutput = true;
$xml2->save($xml2_fname);
}

Rabel
01-04-2012, 04:57 PM
this is the important line
$media2->setAttribute('url', $_POST['content']);

I just need to add
http://mediasrv3.blahblah.net/arch/
before the post content

Any Ideas?

Spookster
01-04-2012, 05:47 PM
If you want to concantenate it to the post content you need to use a .

$media2->setAttribute('url', 'http://mediasrv3.blahblah.net/arch/' . $_POST['content']);

Rabel
01-04-2012, 06:02 PM
Thanks Spookster, i just needed to change + to .

Thanks again
Randy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum