Jump to content

New to PHP please help


unplugged_web

Recommended Posts

Many of the PHP5 functions have PHP4 equivalents posted on the comments pages on php.net. This is what someone posted for file_put_contents:

if (!defined('FILE_APPEND'))  define('FILE_APPEND', 1);if (!function_exists('file_put_contents')){function file_put_contents($n, $d, $flag = false) {	$mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';	$f = @fopen($n, $mode);	if ($f === false) {		return 0;	} else {		if (is_array($d)) $d = implode($d);		$bytes_written = fwrite($f, $d);		fclose($f);		return $bytes_written;	}}}

That function is written to provide the same functionality that is given on the reference page for file_put_contents.

Link to comment
Share on other sites

  • Replies 113
  • Created
  • Last Reply

Thanks I tried that and got an error saying:

warning: Sablotron error on line 17: XML parser error 4: not well-formed (invalid token) in e:\domains\t\thephonecasino.com\user\htdocs\xml_transform.php on line 43Error during transformation of "remote.xml" with "structure.xsl" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct.
but the xml is well formed and I can see the xml-tree in my browser.If I disable that bit of code the the error I get is:
Fatal error: Call to undefined function: file_put_contents() in e:\domains\t\thephonecasino.com\user\htdocs\xml_transform.php on line 37
Link to comment
Share on other sites

I'm not at all surprised the host didn't/couldn't migrate to PHP5. Even if their server OS supported it, they still wouldn't have, as their customers might experience difficulties when migrating. I mean, if this works, even you are going to have trouble, as you'll have to rewrite the code for the XSLT processing (which since already done earlier in this topic shouldn't be that hard).What justsomeguy showed is the definiton of file_put_contents(). The one which I meant for you to uncomment when I said

And move (that is, remove it from that spot, and place) the "/*" before this
//Save a local copy of the remote file at the specified location for a local copy//This will also stript out extra spaces at the beginning and the end of the documentfile_put_contents($xmlFileLocal, trim(file_get_contents($xmlFile)));

You need that in order to enable the file_put_contents() function

I'm really tempted at asking you for a Gobby session (look at my signature), but I'm afraid explaining you how to install it may take longer then trying to solve the problem itself. If you can install it, that'd be great, but if you can't, don't bother.Just to ensure, the XSLT is:
<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:output indent="yes"/>	<xsl:template match="/CasinoInfo">		<!--Parameter addded for performance's sake.		Otherwise double with "../CasinoName" within the for-each-->		<xsl:param name="casino" select="CasinoName"/>		<PhoneCasino>			<xsl:for-each select="Games/*">				<Casino>					<CasinoName>						<xsl:value-of select="$casino"/>					</CasinoName>					<Game>						<xsl:value-of select="title"/>					</Game>					<Winner>						<xsl:value-of select="lastWinner"/>					</Winner>					<won>						<xsl:value-of select="title"/>					</won>						<Jackpot>							<xsl:value-of select="Nudge7/jackpot/progressive/formatted"/>						</Jackpot>				</Casino>			</xsl:for-each>		</PhoneCasino>	</xsl:template>	<!--Just to eliminate some of the extra spaces-->	<xsl:template match="text()">		<xsl:value-of select="normalize-space(.)"/>	</xsl:template></xsl:stylesheet>

And your local copy looks like:

<?xml version="1.0"?><CasinoInfo>  <CasinoName> Casino </CasinoName>  <PartnerName> Casino </PartnerName>  <Generated> 2007-08-02 12:36:48 </Generated>  <Games>   <VideoPoker>	<title> Video Poker </title>	<about> A superb 5-Card Stud Poker game for novices and experts alike. Win 250 times your stake on a Royal Flush! Jacks or better pays out. Install NOW for free! </about>	<lastWinner> GH, London just won 50 pence </lastWinner>   </VideoPoker>   <UnionJackpot>	<title> Union Jackpot </title>	<about> Britain's most patriotic fruit machine. Spin, nudge and hold your way on horizontal or diagonal lines to win. Install NOW for free! </about>	<jackpot>	 <progressive>	  <formatted> 93.49 </formatted>	  <penceInteger> 9349 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> SH, Winsford just won 1.50 </lastWinner>   </UnionJackpot>   <Roulette>	<title> Roulette </title>	<about> Probably the best Casino game in the world... Put a REAL Roulette game on your phone and place your chips on all your favourite combinations and patterns. Install NOW for free! </about>	<lastWinner> JP, Exmouth just won 9.00 </lastWinner>   </Roulette>   <Blackjack>	<title> Blackjack </title>	<about> Beat the dealer to 21 and double your money! Bet as much or as little as you like, from 10p upwards. Install NOW for free! </about>	<lastWinner />   </Blackjack>   <Nudge7>	<title> Nudge7 </title>	<about> Nudge, hold and spin your way to our progressive jackpot which goes up with every spin! Install NOW for free! </about>	<jackpot>	 <progressive>	  <formatted> 5,259.15 </formatted>	  <penceInteger> 525915 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> CG, London just won 3.00 </lastWinner>   </Nudge7>   <MoneyBeach>	<title> Money Beach </title>	<about> Who thought you could ever make money by hitting the beach? You could win up to 50 times your stake! Install NOW for free! </about>	<lastWinner> CM, Kirkcaldy just won 50 pence </lastWinner>   </MoneyBeach>   <LoveMachine>	<title> Love Machine </title>	<about> Oh won't you buy me a diamond ring? (Or failing that a Mercedes Benz). Put a positive spin on Valentine's Day with the Love Machine. </about>	<jackpot>	 <progressive>	  <formatted> 1,576.65 </formatted>	  <penceInteger> 157665 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> LG, Huntly just won 1.50 </lastWinner>   </LoveMachine>   <Hi-Lo>	<title> Hi-Lo </title>	<about> Higher! Lower! Rack up those winnings in our fast, fun and furious Hi Lo cards game! Install NOW for free! </about>	<lastWinner> AM, GRANTOWN-ON-SPEY just won 54 pence </lastWinner>   </Hi-Lo>   <Bingo>	<title> Bingo! </title>	<about> Eyes down for genuine British Bingo hall style action on your mobile. Install NOW for free! </about>	<lastWinner> A in Sunderland just won 10.00 </lastWinner>   </Bingo>  </Games></CasinoInfo>

And your PHP looks like:

<?php//Your files. The saved XSLT file, the remote XML, the location of the local copy and result.$xmlFile = 'http://stats.probability.tv/feed.php?key=mypassword'; //The remote file$xmlFileLocal = 'remote.xml'; //The location of the local copy of the remote file$xsltFile = 'structure.xsl'; //The XSLT file$newFile = 'Marquee.xml'; //The location of the transformed file//Display any PHP errors found further below (if any)ini_set('display_errors','On');//The definition of file_put_contents() in case it's not available which is most likely as that function was added in PHP5.0.0.if (!function_exists('file_put_contents')){if (!defined('FILE_APPEND')) {  define('FILE_APPEND', 1);}function file_put_contents($n, $d, $flag = false){  $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';  $f = @fopen($n, $mode);  if ($f === false)  {	return 0;  }  else  {	if (is_array($d)) $d = implode($d);	$bytes_written = fwrite($f, $d);	fclose($f);	return $bytes_written;  }}}/*//Save a local copy of the remote file at the specified location for a local copy//This will also stript out extra spaces at the beginning and the end of the documentfile_put_contents($xmlFileLocal, trim(file_get_contents($xmlFile)));*///Check if the XSLT extension is availableif (!function_exists('xslt_create')) {die('The XSLT extension is not enabled. Contact your host to enable it.');}//Prepare the XSLT processor.$xh = xslt_create();//Execute the transformationif (!$transformation = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', null, array('/_xml' => file_get_contents($xmlFileLocal), '/_xsl' => file_get_contents($xsltFile)))) {die('Error during transformation of "' . $xmlFileLocal . '" with  "' . $xsltFile . '" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct.');}if (!file_put_contents($newFile, $transformation)) {die('Unable to write "' . $newFile . '"');}//Free the XSLT processor.xslt_free($xh);echo 'The script executed succesfully. A local copy of "' . $xmlFile . '" is available at "' . $xmlFileLocal . '" and a transformed by "' . $xsltFile . '" version is available at "' . $newFile . '".';?>

Damn, I know it works on PHP5. I don't know what's with Salbotron (and thus PHP4).

Link to comment
Share on other sites

Yep just double checked the code and it is all the same. I also checked the php file and it's still outputting the same error:

Warning: Sablotron error on line 10: XML parser error 4: not well-formed (invalid token) in e:\domains\t\thephonecasino.com\user\htdocs\xml_transform.php on line 49Error during transformation of "remote.xml" with "structure.xsl" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct.
Sorry to cause so many problems with this but I really do apprieciate you helping with this.Thanks
Link to comment
Share on other sites

What's line 10 from the XML anyway?

Jacks or better pays out. Install NOW for free! </about>

or

<lastWinner> GH, London just won 50 pence </lastWinner>

Try removing the "!" in the first, or perhaps the "," in the later.Ohhh... actually, don't bother. Figuring out a method to automatically replace whatever characters are invalid is going to be a BIG pain... for me at least. I can't tell how comfy would justsomeguy feel about it (I'm talking about complex regex replacement(s) here).Find another host with PHP5 and speak to them beforehand if they could enable the XSL extension. If Salbotron is THAT unstable (I haven't worked much with it, so I can't really say I've ever experienced any such problems), then you need to find an alternative, and there's no better for PHP then libxslt, which is available for PHP5.

Link to comment
Share on other sites

What's line 10 from the XML anyway?
Jacks or better pays out. Install NOW for free! </about>

or

<lastWinner> GH, London just won 50 pence </lastWinner>

Try removing the "!" in the first, or perhapsthe "," in the later.Ohhh... actually, don't bother. Figuring out a method to automatically replace whatever characters are invalid is going to be a BIG pain... for me at least. I can't tell how comfy would justsomeguy feel about it (I'm talking about complex regex replacement(s) here).Find another host with PHP5 and speak to them beforehand if they could enable the XSL extension. If Salbotron is THAT unstable (I haven't worked much with it, so I can't really say I've ever experienced any such problems), then you need to find an alternative, and there's no better for PHP then libxslt, which is available for PHP5.

Line 10 is:
	<lastWinner> GH, London just won 50 pence </lastWinner>

I think your right though I should speak to my boss about transferring the site again.Thanks

Link to comment
Share on other sites

  • 3 months later...

Sorry I'm back again. I'm now on a server using php5, but I still can't get this to work. I used

<?php//Your files. The saved XSLT file, the remote XML, the location of the local copy and result.$xmlFile = 'http://stats.probability.tv/feed.php?key=mypasskey'; //The remote file$xmlFileLocal = 'remote.xml'; //The location of the local copy$xsltFile = 'structure.xsl'; //The XSLT file$newFile = 'Marquee.xml'; //The location of the transformed file//Display any PHP errors found further below (if any)ini_set('display_errors','On');//Verify the file paths.if (!file_exists($xmlFile)) {die('No XML file at "' . $xmlFile . '". Verify the file exists and you have permissions to view it. Also check for spelling mistakes');}if (!file_exists($xsltFile)) {die('No XSLT file at "' . $xsltFile . '". Verify the file exists and you have permissions to view it. Also check for spelling mistakes');}//Prepare the XML file$xml = new DomDocument;if (!$xml->loadXML(trim(file_get_contents($xmlFile)))) {/*I've only used loadXML() because you said the XML has spaces before the prolog.That may cause problems if just load()-ed. I'm not sure though.In general, you should use load() as done below with the XSLT file.*/die('XML file "' . $xmlFile . '" is not well-formed.');}//Indent the file that would be saved$xml->formatOutput = true;//Save a local copy of the remote file before transforming it$xml->save($xmlFileLocal);//Prepare the XSLT file$xsl = new DomDocument;if (!$xsl->load($xsltFile)) {die('XSLT file "' . $xsltFile . '" is not well-formed XML document.');}//Ensure the XSLT processor is availableif (!class_exists('XSLTProcessor')) {die('The PHP XSL extension is not available and it is needed for this to work. Contact your host to enable it.');}//Load the XSLT processor$xslt = new XSLTProcessor;$xslt->importStylesheet($xsl);//Tell the XSLT stylesheet the name of your new file$xslt->setParameter(null, 'original', $newFile);//Execute the transformationif (!$xslt->transformToURI($xml, $newFile)) {die('Error during transformation of "' . $xmlFile . '" with  "' . $xsltFile . '" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct. Other possibilies include disability to write "' . $newFile . '"');}echo 'The script executed succesfully. A local copy of "' . $xmlFile . '" is available at "' . $xmlFileLocal . '" and a transformed by "' . $xsltFile . '" version is available at "' . $newFile . '".';?>

but I get an error saying

No XML file at "http://stats.probability.tv/feed.php?key=mypasskey". Verify the file exists and you have permissions to view it. Also check for spelling mistakes
but I've checked and the file is definitely there and the passkey part of the address gives me permission to view it.Sorry to be a pain with this again
Link to comment
Share on other sites

So if I change the code to:

<?phpif (!defined('FILE_APPEND'))  define('FILE_APPEND', 1);if (!function_exists('file_put_contents')){function file_put_contents($n, $d, $flag = false){  $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';  $f = @fopen($n, $mode);  if ($f === false)  {    return 0;  }  else  {    if (is_array($d)) $d = implode($d);    $bytes_written = fwrite($f, $d);    fclose($f);    return $bytes_written;  }}}$xml = "http://stats.probability.tv/feed.php?key=mypasskey";$destination = dirname(__FILE__) . "/saved.xml"; //save the xml in a file called saved in the current folder$data = file_get_contents($xml);if (!$bytes = file_put_contents($destination, trim($data)))  echo "Writing to {$destination} failed";else  echo "Succesfully wrote {$destination}, saved {$bytes} bytes";//Your files. The saved XSLT file, the remote XML, the location of the local copy and result.$xmlFile = 'saved.xml'; //The remote file$xmlFileLocal = 'remote.xml'; //The location of the local copy$xsltFile = 'structure.xsl'; //The XSLT file$newFile = 'Marquee.xml'; //The location of the transformed file//Display any PHP errors found further below (if any)ini_set('display_errors','On');//Verify the file paths.if (!file_exists($xmlFile)) {die('No XML file at "' . $xmlFile . '". Verify the file exists and you have permissions to view it. Also check for spelling mistakes');}if (!file_exists($xsltFile)) {die('No XSLT file at "' . $xsltFile . '". Verify the file exists and you have permissions to view it. Also check for spelling mistakes');}//Prepare the XML file$xml = new DomDocument;if (!$xml->load(trim(file_get_contents($xmlFile)))) {die('XML file "' . $xmlFile . '" is not well-formed.');}//Indent the file that would be saved$xml->formatOutput = true;//Save a local copy of the remote file before transforming it$xml->save($xmlFileLocal);//Prepare the XSLT file$xsl = new DomDocument;if (!$xsl->load($xsltFile)) {die('XSLT file "' . $xsltFile . '" is not well-formed XML document.');}//Ensure the XSLT processor is availableif (!class_exists('XSLTProcessor')) {die('The PHP XSL extension is not available and it is needed for this to work. Contact your host to enable it.');}//Load the XSLT processor$xslt = new XSLTProcessor;$xslt->importStylesheet($xsl);//Tell the XSLT stylesheet the name of your new file$xslt->setParameter(null, 'original', $newFile);//Execute the transformationif (!$xslt->transformToURI($xml, $newFile)) {die('Error during transformation of "' . $xmlFile . '" with  "' . $xsltFile . '" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct. Other possibilies include disability to write "' . $newFile . '"');}echo 'The script executed succesfully. A local copy of "' . $xmlFile . '" is available at "' . $xmlFileLocal . '" and a transformed by "' . $xsltFile . '" version is available at "' . $newFile . '".';?>

Would it work then?

Link to comment
Share on other sites

No. It's the file_exists($xmlFile) you should remove.... strange though. I thought it could be used with URL wrappers as well. Oh well...just try this:

<?php//Your files. The saved XSLT file, the remote XML, the location of the local copy and result.$xmlFile = 'http://stats.probability.tv/feed.php?key=mypasskey'; //The remote file$xmlFileLocal = 'remote.xml'; //The location of the local copy$xsltFile = 'structure.xsl'; //The XSLT file$newFile = 'Marquee.xml'; //The location of the transformed file//Display any PHP errors found further below (if any)ini_set('display_errors','On');//Verify the file paths.if (!file_put_contents($xmlFileLocal,trim(file_get_contents($xmlFile)))) {die('No XML file at "' . $xmlFile . '" or file was not succesfully saved locally. Verify the file at the URL exists and you have permissions to view it. Also check for spelling mistakes. Also check if the local copy is written and has the data in it.');}if (!file_exists($xsltFile)) {die('No XSLT file at "' . $xsltFile . '". Verify the file exists and you have permissions to view it. Also check for spelling mistakes.');}//Prepare the XML file$xml = new DomDocument;if (!$xml->load($xmlFileLocal)) {die('XML file "' . $xmlFile . '" is not well-formed.');}//Prepare the XSLT file$xsl = new DomDocument;if (!$xsl->load($xsltFile)) {die('XSLT file "' . $xsltFile . '" is not well-formed XML document.');}//Ensure the XSLT processor is availableif (!class_exists('XSLTProcessor')) {die('The PHP XSL extension is not available and it is needed for this to work. Contact your host to enable it.');}//Load the XSLT processor$xslt = new XSLTProcessor;$xslt->importStylesheet($xsl);//Tell the XSLT stylesheet the name of your new file$xslt->setParameter(null, 'original', $newFile);//Execute the transformationif (!$xslt->transformToURI($xml, $newFile)) {die('Error during transformation of "' . $xmlFile . '" with  "' . $xsltFile . '" as stylesheet. Possibly an endless loop or illegal XSLT/XPath construct. Other possibilies include disability to write "' . $newFile . '"');}echo 'The script executed succesfully. A local copy of "' . $xmlFile . '" should be available at "' . $xmlFileLocal . '" and a transformed by "' . $xsltFile . '" version should be available at "' . $newFile . '".';?>

Link to comment
Share on other sites

Thanks, I tried that, but got an error saying:

Warning: file_put_contents(remote.xml) [function.file-put-contents]: failed to open stream: Permission denied in /home/fhlinux159/d/mydomain.com/user/htdocs/phonecasino/xml_transform.php on line 12
Line 12 is:
if (!file_put_contents($xmlFileLocal,trim(file_get_contents($xmlFile)))) {

It said that permission was denied, but I have access to both the domain the php file is hosted with and the url that has the xml file?

Link to comment
Share on other sites

Thanks, I tried that, but got an error saying:Line 12 is:
if (!file_put_contents($xmlFileLocal,trim(file_get_contents($xmlFile)))) {

It said that permission was denied, but I have access to both the domain the php file is hosted with and the url that has the xml file?

Are you sure? Create another PHP file (in the same folder as the other one), and in it, have just
<?phpini_set('display_errors','On');$bytes = file_put_contents('test.txt','This is some text created just for the test');var_dump($bytes);?>

The output of this should be some sort of a number (which shows the number of bytes written to the file, so assuming a character is a byte, it should be somewhere around 43 bytes). A file named 'test.txt' should be created in the same folder, having the text 'This is some text created just for the test' as it's contents. If you don't get an error... there's something else weird going on. If you do, there are a few other things that we could try, but if none work, you'll have to contact the host for support on this one, so if you're in a hurry, ask them now.

Link to comment
Share on other sites

Are you sure? Create another PHP file (in the same folder as the other one), and in it, have just
<?phpini_set('display_errors','On');$bytes = file_put_contents('test.txt','This is some text created just for the test');var_dump($bytes);?>

The output of this should be some sort of a number (which shows the number of bytes written to the file, so assuming a character is a byte, it should be somewhere around 43 bytes). A file named 'test.txt' should be created in the same folder, having the text 'This is some text created just for the test' as it's contents. If you don't get an error... there's something else weird going on. If you do, there are a few other things that we could try, but if none work, you'll have to contact the host for support on this one, so if you're in a hurry, ask them now.

Okay I ran the script and didn't get any errors at all, although no file was generated :) Sorry, I guess I need to contact the host, but do you have any idea what's happening (or not happening)?
Link to comment
Share on other sites

Okay I ran the script and didn't get any errors at all, although no file was generated :) Sorry, I guess I need to contact the host, but do you have any idea what's happening (or not happening)?
Now there's a combo I was not expecting. How is it always what I don't expect?Well... the file was not generated, so that pretty much breaks anything else anyway.Try this one instead:
<?phpini_set('display_errors','On');$bytes = file_put_contents(getcwd() . '/test.txt','This is some text created just for the test');var_dump($bytes);?>

This should guarantee that you're creating the file in the same folder. It's possible the file was created, but the location is out of your reach (hey, if that is right, then that makes you a sort of a hacker... you could have written a file of any size there, eventually damaging the host's server :) ). If even this fails, check that you actually have enough free space on the host (though it's unlikely you won't have 1kb or more to spare).

Link to comment
Share on other sites

Now there's a combo I was not expecting. How is it always what I don't expect?Well... the file was not generated, so that pretty much breaks anything else anyway.Try this one instead:
<?phpini_set('display_errors','On');$bytes = file_put_contents(getcwd() . '/test.txt','This is some text created just for the test');var_dump($bytes);?>

This should guarantee that you're creating the file in the same folder. It's possible the file was created, but the location is out of your reach (hey, if that is right, then that makes you a sort of a hacker... you could have written a file of any size there, eventually damaging the host's server :) ). If even this fails, check that you actually have enough free space on the host (though it's unlikely you won't have 1kb or more to spare).

Okay, it worked. The file was create and after running the script the page showed: int(43)
Link to comment
Share on other sites

Great. Then, from the other PHP file, replace

$xmlFileLocal = 'remote.xml';

with

$xmlFileLocal = getcwd() . '/remote.xml';

and see how it goes.If it again fails with another error message (I don't know, but since it failed so many times already, I'm starting to see it coming), try to also do this for the XSLT file and the new file:

$xsltFile = getcwd() . '/structure.xsl'; //The XSLT file$newFile = getcwd() . '/Marquee.xml'; //The location of the transformed file

(ensuring all of those files are in the same folder as the PHP file of course)

Link to comment
Share on other sites

Great. Then, from the other PHP file, replace
$xmlFileLocal = 'remote.xml';

with

$xmlFileLocal = getcwd() . '/remote.xml';

and see how it goes.If it again fails with another error message (I don't know, but since it failed so many times already, I'm starting to see it coming), try to also do this for the XSLT file and the new file:

$xsltFile = getcwd() . '/structure.xsl'; //The XSLT file$newFile = getcwd() . '/Marquee.xml'; //The location of the transformed file

(ensuring all of those files are in the same folder as the PHP file of course)

Thanks, I've just been asked to do some work on another site so will try this as soon as I can and then let you know how I get on. Thanks again for your help
Link to comment
Share on other sites

Thanks, I've just been asked to do some work on another site so will try this as soon as I can and then let you know how I get on. Thanks again for your help
Sorry more errors, I changed both bits of code and the error I got was:Warning: file_put_contents(/home/fhlinux159/d/mydomain.com/user/htdocs/phone/remote.xml) [function.file-put-contents]: failed to open stream: Permission denied in /home/fhlinux159/d/mydomain.com/user/htdocs/phone/xml_transform.php on line 12Line 12 is:if (!file_put_contents($xmlFileLocal,trim(file_get_contents($xmlFile)))) {
Link to comment
Share on other sites

Does the file already exist? Check the permissions on it to make sure that it is writeable.
Actually, if it exists, delete it. It shouldn't exist on the first place. It, as well as $newFile should be created during the script's execution, and as far as I'm aware, they are then made writable as well.
Link to comment
Share on other sites

Actually, if it exists, delete it. It shouldn't exist on the first place. It, as well as $newFile should be created during the script's execution, and as far as I'm aware, they are then made writable as well.
I deleted both of the files and then ran the script again. It created the $xmlFileLocal file, but not the $newFile file. It also came up with an error saying:
Warning: DOMDocument::loadXML() [function.DOMDocument-loadXML]: Input is not proper UTF-8, indicate encoding ! Bytes: 0xA3 0x39 0x2E 0x36 in Entity, line: 20 in /home/fhlinux159/d/mydomain.com/user/htdocs/phone/xml_transform.php on line 21XML file "http://stats.probability.tv/feed.php?key=mypasskey" is not well-formed.
Line 21 in the php file is:
if (!$xml->loadXML(trim(file_get_contents($xmlFile)))) {

and line 21 in the xml file is:

	<title> Roulette </title>

Link to comment
Share on other sites

What is the contents of the XML file again?Just for reference, in the error message, the place in the XML is the first mentioned line (20), but even so, showing the whole XML would be better. And if you can give the URI of your local copy, or better yet - the original one, we could reproduce this in our own environments (I sure can, now that you have PHP5). Your PHP is fine. It crashed in the exact way it should have in such an event.

Link to comment
Share on other sites

What is the contents of the XML file again?Just for reference, in the error message, the place in the XML is the first mentioned line (20), but even so, showing the whole XML would be better. And if you can give the URI of your local copy, or better yet - the original one, we could reproduce this in our own environments (I sure can, now that you have PHP5). Your PHP is fine. It crashed in the exact way it should have in such an event.
The contents of the xml file (the one saved via the php) are:
<?xml version="1.0"?> <CasinoInfo>  <CasinoName> Casino </CasinoName>  <PartnerName> Casino </PartnerName>  <Generated> 2007-11-28 10:09:57 </Generated>  <Games>   <Bingo>	<title> Bingo! </title>	<about> Eyes down for genuine British Bingo hall style action on your mobile. Install NOW for free! </about>	<lastWinner> M in Ilkeston just won &#163;8.33 </lastWinner>   </Bingo>   <Blackjack>	<title> Blackjack </title>	<about> Beat the dealer to 21 and double your money! Bet as much or as little as you like, from 10p upwards. Install NOW for free! </about>	<lastWinner />   </Blackjack>   <Roulette>	<title> Roulette </title>	<about> Probably the best Casino game in the world... Put a REAL Roulette game on your phone and place your chips on all your favourite combinations and patterns. Install NOW for free! </about>	<lastWinner> PS, Ellesmere Port just won £9.60 </lastWinner>   </Roulette>   <Nudge7>	<title> Nudge7 </title>	<about> Nudge, hold and spin your way to our progressive jackpot which goes up with every spin! Install NOW for free! </about>	<jackpot>	 <progressive>	  <formatted> £1,401.57 </formatted>	  <penceInteger> 140157 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> PM, Stoke-On-Trent just won £3.00 </lastWinner>   </Nudge7>   <MoneyBeachSlots>	<title> Money Beach Slots </title>	<about> Who thought you could ever make money by hitting the beach? You could win up to 50 times your stake! Install NOW for free! </about>	<lastWinner> PM, Stoke-On-Trent just won £1.00 </lastWinner>   </MoneyBeachSlots>   <VideoPoker>	<title> Video Poker </title>	<about> A superb 5-Card Stud Poker game for novices and experts alike. Win 250 times your stake on a Royal Flush! Jacks or better pays out. Install NOW for free! </about>	<lastWinner> CL, PL2 just won £1.00 </lastWinner>   </VideoPoker>   <Hi-Lo>	<title> Hi-Lo </title>	<about> Higher! Lower! Rack up those winnings in our fast, fun and furious Hi Lo cards game! Install NOW for free! </about>	<lastWinner> LS, CHESTER LE STREET just won 13 pence </lastWinner>   </Hi-Lo>   <LoveMachine>	<title> Love Machine </title>	<about> Oh won't you buy me a diamond ring? (Or failing that a Mercedes Benz). Put a positive spin on Valentine's Day with the Love Machine. </about>	<jackpot>	 <progressive>	  <formatted> £3,120.25 </formatted>	  <penceInteger> 312025 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> PM, Stoke-On-Trent just won 50 pence </lastWinner>   </LoveMachine>   <UnionJackpot>	<title> Union Jackpot </title>	<about> Britain's most patriotic fruit machine. Spin, nudge and hold your way on horizontal or diagonal lines to win. Install NOW for free! </about>	<jackpot>	 <progressive>	  <formatted> £785.55 </formatted>	  <penceInteger> 78555 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> MG, PLYMOUTH just won £1.50 </lastWinner>   </UnionJackpot>  </Games> </CasinoInfo>

and the contents of the original xml file (http://stats.probability.tv/feed.php?key=mypasskey) are:

<?xml version="1.0"?> <CasinoInfo>  <CasinoName> Casino </CasinoName>  <PartnerName> Casino </PartnerName>  <Generated> 2007-11-28 12:54:42 </Generated>  <Games>   <Bingo>	<title> Bingo! </title>	<about> Eyes down for genuine British Bingo hall style action on your mobile. Install NOW for free! </about>	<lastWinner> L in Maidstone just won &#163;5.00 </lastWinner>   </Bingo>   <Blackjack>	<title> Blackjack </title>	<about> Beat the dealer to 21 and double your money! Bet as much or as little as you like, from 10p upwards. Install NOW for free! </about>	<lastWinner />   </Blackjack>   <Roulette>	<title> Roulette </title>	<about> Probably the best Casino game in the world... Put a REAL Roulette game on your phone and place your chips on all your favourite combinations and patterns. Install NOW for free! </about>	<lastWinner> PS, Ellesmere Port just won £9.60 </lastWinner>   </Roulette>   <Nudge7>	<title> Nudge7 </title>	<about> Nudge, hold and spin your way to our progressive jackpot which goes up with every spin! Install NOW for free! </about>	<jackpot>	 <progressive>	  <formatted> £1,424.67 </formatted>	  <penceInteger> 142467 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> PM, Stoke-On-Trent just won £3.00 </lastWinner>   </Nudge7>   <MoneyBeachSlots>	<title> Money Beach Slots </title>	<about> Who thought you could ever make money by hitting the beach? You could win up to 50 times your stake! Install NOW for free! </about>	<lastWinner> PM, Stoke-On-Trent just won £1.00 </lastWinner>   </MoneyBeachSlots>   <VideoPoker>	<title> Video Poker </title>	<about> A superb 5-Card Stud Poker game for novices and experts alike. Win 250 times your stake on a Royal Flush! Jacks or better pays out. Install NOW for free! </about>	<lastWinner> CL, PL2 just won £1.00 </lastWinner>   </VideoPoker>   <Hi-Lo>	<title> Hi-Lo </title>	<about> Higher! Lower! Rack up those winnings in our fast, fun and furious Hi Lo cards game! Install NOW for free! </about>	<lastWinner> LS, CHESTER LE STREET just won 13 pence </lastWinner>   </Hi-Lo>   <LoveMachine>	<title> Love Machine </title>	<about> Oh won't you buy me a diamond ring? (Or failing that a Mercedes Benz). Put a positive spin on Valentine's Day with the Love Machine. </about>	<jackpot>	 <progressive>	  <formatted> £3,121.70 </formatted>	  <penceInteger> 312170 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> PM, Stoke-On-Trent just won 50 pence </lastWinner>   </LoveMachine>   <UnionJackpot>	<title> Union Jackpot </title>	<about> Britain's most patriotic fruit machine. Spin, nudge and hold your way on horizontal or diagonal lines to win. Install NOW for free! </about>	<jackpot>	 <progressive>	  <formatted> £785.55 </formatted>	  <penceInteger> 78555 </penceInteger>	 </progressive>	</jackpot>	<lastWinner> MG, PLYMOUTH just won £1.50 </lastWinner>   </UnionJackpot>  </Games> </CasinoInfo>

although there's a three line space gap at the top, but that hasn't shown up here

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...