简体   繁体   中英

Help with basic php and xml needed

I'm really new to xml, with this being my first dip into it.

I'm trying to add some text to an image using php and xml.

I keep getting the following error: Parse error: syntax error, unexpected '}' in /home/a8744502/public_html/userbar.php on line 18

Below is my code.

<?php
header ("Content-type: image/jpeg");

$doc = new DOMDocument();
$doc->load( "http://phogue.net/feed/". LIBXML_DTDLOAD );

$procon = $doc->getElementsByTagName( "procon" );

$packages = $procon->getElementsByTagName( "package" );
$value = 0;

foreach($packages as $package)
{
  $downloadsA = $package->getElementsByTagName( "downloads" );
  $downloads = $downloadsA->item(0)->nodeValue;

  $value = $downloads + $value
}                                           
$font  = "visitor1.tff";
$font  = 4;
$im = ImageCreateFromjpeg("procon_plugindeveloper.jpg");
$x = 360;
$y = 0;
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 255, 255, 255);
imagestring ($im, $font, $x, $y,  $value, $text_color);
imagejpeg ($im);
?>

The xml file is of the form

<procon>
-<packages>
--<package>
---<downloads>
---</doanloads>
--</package>

--<package>
---<downloads>
---</doanloads>
--</package>

--<package>
---<downloads>
---</doanloads>
--</package>


-</packages>
</procon>

The idea is that it should print out the sum of all the downloads tags that are contained in .

Any help is appreciated :-)

  $value = $downloads + $value
}   

missing a ;

can't say if that'll make it work though.

also you probably mean $value .= $downloads + $value; to add on top of the $value variable, else it will just get overwritten each iteration

edit:

you can also just do:

$value += $download; //$value equals $value + $download

to really confuse you !

Missing a ; on the last line of your foreach . :)

This is a PHP error, nothing to do with XML. This line:

$value = $downloads + $value

needs a semicolon at the end...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM