Jump to content
unplugged_web

New to PHP please help

Recommended Posts

It works fine when with the local copy of mine.Try to use the local copy you have, instead of the directly fetched one.I.e., use this:

//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 "' . $xmlFileLocal . '" is not well-formed.');}

as shown in the previous full code I gave you (though this time I replaced $xmlFile with $xmlFileLocal as I should have done before)This will show whether your local copy suffers from this same bug. And if it does... hm... no, it's not encoding. I tried saving the file as ANSI, and even though some characters were turned into "?", PHP was still able to load it.Well, as the error message says, you may also try to explicitly specify that's UTF-8 text, though I doubht it will help, since the error message says it's not a valid UTF-8 text. Heck, what are those bytes - 0xA3 0x39 0x2E 0x36 ?I'll have to check those out.... until then, try the above reccomendations.

Share this post


Link to post
Share on other sites
It works fine when with the local copy of mine.Try to use the local copy you have, instead of the directly fetched one.I.e., use this:
//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 "' . $xmlFileLocal . '" is not well-formed.');}

as shown in the previous full code I gave you (though this time I replaced $xmlFile with $xmlFileLocal as I should have done before)This will show whether your local copy suffers from this same bug. And if it does... hm... no, it's not encoding. I tried saving the file as ANSI, and even though some characters were turned into "?", PHP was still able to load it.Well, as the error message says, you may also try to explicitly specify that's UTF-8 text, though I doubht it will help, since the error message says it's not a valid UTF-8 text. Heck, what are those bytes - 0xA3 0x39 0x2E 0x36 ?I'll have to check those out.... until then, try the above reccomendations.

Sorry, still the same error message as before

Share this post


Link to post
Share on other sites

It seems the encodings get messed up, though I wonder how could they be fixed...hmm... do you have ivonv enabled?I'm assuming you do have it, since you have PHP5. Let's try to convert the input document to a valid UTF-8 document when we save it. Replace:

if (!file_put_contents($xmlFileLocal,trim(file_get_contents($xmlFile)))) {

with

if (!file_put_contents($xmlFileLocal,iconv('','UTF-8//TRANSLIT',trim(file_get_contents($xmlFile))))) {

And see how that goes.The above fix should ensure the local copy is valid UTF-8 (in contrast to the error message), and thus is parsable by DOMDocument::load().

Share this post


Link to post
Share on other sites
It seems the encodings get messed up, though I wonder how could they be fixed...hmm... do you have ivonv enabled?I'm assuming you do have it, since you have PHP5. Let's try to convert the input document to a valid UTF-8 document when we save it. Replace:
if (!file_put_contents($xmlFileLocal,trim(file_get_contents($xmlFile)))) {

with

if (!file_put_contents($xmlFileLocal,iconv('','UTF-8//TRANSLIT',trim(file_get_contents($xmlFile))))) {

And see how that goes.The above fix should ensure the local copy is valid UTF-8 (in contrast to the error message), and thus is parsable by DOMDocument::load().

I got a load more error messages this time, sorry:
Notice: iconv() [function.iconv]: Detected an illegal character in input string in /home/fhlinux159/d/mydomain.com/user/htdocs/phone/xml_transform.php on line 12Warning: DOMDocument::load() [function.DOMDocument-load]: Premature end of data in tag lastWinner line 20 in /home/fhlinux159/d/mydomain.com/user/htdocs/phone/remote.xml, line: 20 in /home/fhlinux159/d/mydomain.com/user/htdocs/phone/xml_transform.php on line 21Warning: DOMDocument::load() [function.DOMDocument-load]: Premature end of data in tag Roulette line 17 in /home/fhlinux159/d/mydomain.com/user/htdocs/phone/remote.xml, line: 20 in /home/fhlinux159/d/mydomain.com/user/htdocs/phone/xml_transform.php on line 21Warning: DOMDocument::load() [function.DOMDocument-load]: Premature end of data in tag Games line 6 in /home/fhlinux159/d/mydomain.com/user/htdocs/phone/remote.xml, line: 20 in /home/fhlinux159/d/mydomain.com/user/htdocs/phone/xml_transform.php on line 21Warning: DOMDocument::load() [function.DOMDocument-load]: Premature end of data in tag CasinoInfo line 2 in /home/fhlinux159/d/mydomain.com/user/htdocs/phone/remote.xml, line: 20 in /home/fhlinux159/d/dmydomain.com/user/htdocs/phone/xml_transform.php on line 21XML file "/home/fhlinux159/d/mydomain.com/user/htdocs/phone/remote.xml" is not well-formed.
I thought that I'd post the php code as well in case I got anything in the wrong place:
<?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 = getcwd() . '/remote.xml';$xsltFile = getcwd() . '/structure.xsl'; //The XSLT file$newFile = getcwd() . '/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,iconv('','UTF-8//TRANSLIT',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 "' . $xmlFileLocal . '" 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 . '".';?>

Thanks for helping me with this

Share this post


Link to post
Share on other sites

Try to replace the

//TRANSLIT

part on that same line with

//IGNORE

but know that the pound sign, and all illegal characters will be lost. If you really want them, they could be readded with the XSLT, but for now, let's focus on having ANY output.Just to be on the safe side, I mean this:

if (!file_put_contents($xmlFileLocal,iconv('','UTF-8//TRANSLIT',trim(file_get_contents($xmlFile))))) {

be replaced like this:

if (!file_put_contents($xmlFileLocal,iconv('','UTF-8//IGNORE',trim(file_get_contents($xmlFile))))) {

Share this post


Link to post
Share on other sites
Try to replace the
//TRANSLIT

part on that same line with

//IGNORE

but know that the pound sign, and all illegal characters will be lost. If you really want them, they could be readded with the XSLT, but for now, let's focus on having ANY output.Just to be on the safe side, I mean this:

if (!file_put_contents($xmlFileLocal,iconv('','UTF-8//TRANSLIT',trim(file_get_contents($xmlFile))))) {

be replaced like this:

if (!file_put_contents($xmlFileLocal,iconv('','UTF-8//IGNORE',trim(file_get_contents($xmlFile))))) {

Yipee that worked! Thank you :) Although as you said the pound symbols did disappear, but so did the jackpot amounts (although both were there in the remote.xml file)

Share this post


Link to post
Share on other sites

Great. Now, in case you want your pounds back (pun intended), add the pound sign right before the corresponding value-of stament in the XSLT. In the case :lol:of the jackpot, this would be the part:

						<Jackpot>							<xsl:value-of select="Nudge7/jackpot/progressive/formatted"/>						</Jackpot>

which should then be just

						<Jackpot>£<xsl:value-of select="Nudge7/jackpot/progressive/formatted"/></Jackpot>

if that doesn't work, replace "£" with & 163; (but remove the space between the & and the number. I've added it because of the forum).

Share this post


Link to post
Share on other sites
Great. Now, in case you want your pounds back (pun intended), add the pound sign right before the corresponding value-of stament in the XSLT. In the case :lol:of the jackpot, this would be the part:
						<Jackpot>							<xsl:value-of select="Nudge7/jackpot/progressive/formatted"/>						</Jackpot>

which should then be just

						<Jackpot>£<xsl:value-of select="Nudge7/jackpot/progressive/formatted"/></Jackpot>

if that doesn't work, replace "£" with & 163; (but remove the space between the & and the number. I've added it because of the forum).

Thats great thank you, but how do I get the actual amount of money into the jackpot field as well? When the £ symbol is removed the amount is removed too.

Share this post


Link to post
Share on other sites

Oh. Right.Well, there are two ways I can think of, but let's go with what SHOULD be the safer one.In the XSLT, use the penceInteger value instead of the formatted one, and format it yourself, like:

<Jackpot>£<xsl:value-of select="format-number(jackpot/progressive/penceInteger div 100,'###,###.00')"/></Jackpot>

I undestand the formatted value is gone, but at least the penceInteger is there, right?

Share this post


Link to post
Share on other sites
Oh. Right.Well, there are two ways I can think of, but let's go with what SHOULD be the safer one.In the XSLT, use the penceInteger value instead of the formatted one, and format it yourself, like:
<Jackpot>£<xsl:value-of select="format-number(jackpot/progressive/penceInteger div 100,'###,###.00')"/></Jackpot>

I undestand the formatted value is gone, but at least the penceInteger is there, right?

That put the jackpot back for some of the jackpot fields, but is it possible to have one jackpot field repeat in all of the fields? ie have the bingo jackpot (say £70.00) repeat in every jackpot field?Thanks

Share this post


Link to post
Share on other sites

You mean everywhere there is no jackpot? Yes, by a simple condition in the place of the current <Jackpot/> in the XSLT:

<Jackpot>£<xsl:choose>								<xsl:when test="jackpot">									<xsl:value-of select="format-number(jackpot/progressive/penceInteger div 100,'###,###.00')"/>								</xsl:when>								<xsl:otherwise>70.00</xsl:otherwise>							</xsl:choose></Jackpot>

(indendation added by my editor because of the rest of the stylesheet)

Share this post


Link to post
Share on other sites
You mean everywhere there is no jackpot? Yes, by a simple condition in the place of the current <Jackpot/> in the XSLT:
<Jackpot>£<xsl:choose>								<xsl:when test="jackpot">									<xsl:value-of select="format-number(jackpot/progressive/penceInteger div 100,'###,###.00')"/>								</xsl:when>								<xsl:otherwise>70.00</xsl:otherwise>							</xsl:choose></Jackpot>

(indendation added by my editor because of the rest of the stylesheet)

I want the jackpot for bingo to be put into every jackpot field so that every jackpot field will be the same, will that work for this?

Share this post


Link to post
Share on other sites

Uhh... bingo doesn't have a jackpot.If you want to define your custom jackpot, then just replace all of the above with the contents you want as a jackpot i.e.

<Jackpot>£70.00</Jackpot>

This will add add a Jackpot to every game with a constant value of 70.00 pounds.If you want to use the Jackpot of Bingo everywhere and this default value if Bingo doesn't have a Jackpot (as in the above case), use this:

<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:output indent="yes"/>	<xsl:param name="original" select="Marquee.xml"/>	<xsl:param name="jackpot">		<xsl:choose>			<xsl:when test="/CasinoInfo/Games/Bingo/jackpot">				<xsl:value-of select="format-number(/CasinoInfo/Games/Bingo/jackpot/progressive/penceInteger div 100,'###,###.00')"/>			</xsl:when>			<xsl:otherwise>70.00</xsl:otherwise>		</xsl:choose>	</xsl:param>	<xsl:template match="/CasinoInfo">		<!--Parameter addded for performance's sake.		Otherwise doable with "../CasinoName" within the for-each-->		<xsl:param name="casino" select="CasinoName"/>		<PhoneCasino>			<xsl:copy-of select="document($original)/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="about"/>					</won>					<Jackpot>£<xsl:value-of select="$jackpot"/></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>

This stylesheet also gives you the additional ability to set the exact Jakpot you want from PHP by just adding:

$xslt->setParameter(null, 'jackpot', '70.00');

(if you look at the code, you'll know where to put that if you want it)

Share this post


Link to post
Share on other sites
Uhh... bingo doesn't have a jackpot.If you want to define your custom jackpot, then just replace all of the above with the contents you want as a jackpot i.e.
<Jackpot>£70.00</Jackpot>

This will add add a Jackpot to every game with a constant value of 70.00 pounds.If you want to use the Jackpot of Bingo everywhere and this default value if Bingo doesn't have a Jackpot (as in the above case), use this:

<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:output indent="yes"/>	<xsl:param name="original" select="Marquee.xml"/>	<xsl:param name="jackpot">		<xsl:choose>			<xsl:when test="/CasinoInfo/Games/Bingo/jackpot">				<xsl:value-of select="format-number(/CasinoInfo/Games/Bingo/jackpot/progressive/penceInteger div 100,'###,###.00')"/>			</xsl:when>			<xsl:otherwise>70.00</xsl:otherwise>		</xsl:choose>	</xsl:param>	<xsl:template match="/CasinoInfo">		<!--Parameter addded for performance's sake.		Otherwise doable with "../CasinoName" within the for-each-->		<xsl:param name="casino" select="CasinoName"/>		<PhoneCasino>			<xsl:copy-of select="document($original)/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="about"/>					</won>					<Jackpot>£<xsl:value-of select="$jackpot"/></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>

This stylesheet also gives you the additional ability to set the exact Jakpot you want from PHP by just adding:

$xslt->setParameter(null, 'jackpot', '70.00');

(if you look at the code, you'll know where to put that if you want it)

Thank you so much for all of your help. It now works perfectly :)

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...