PHP error.

Associate
Joined
18 Nov 2003
Posts
1,311
Location
Newcastle
Anyone help me out on this one please?

Im trying to use this code on a website... but when i go to actually load the file i get...

Parse error: parse error, unexpected '}' in /usr/local/apache/htdocs/weather.php on line 16

Below is the code im trying to use. Could someone take a look at it and tell me whats up please?

Cheers. :)

PHP:
<?php
if( ! ($fp = fopen( "http://xml.weather.yahoo.com/forecastrss?p=UKXX0047&u=c","r" )) )
$xml_current_tag_state = ';
function startElementHandler( $parser, $element_name, $element_attribs )
{
global $property_data;
global $xml_current_tag_state;
$xml_current_tag_state = $element_name;
}
function endElementHandler( $parser, $element_name )
{
global $property_data;
global $xml_current_tag_state;
$xml_current_tag_state = ';
if( $element_name == "CHANNEL" );
}
function characterDataHandler( $parser , $data )
{
global $property_data;
global $xml_current_tag_state;
if( $xml_current_tag_state == ' )
{
return;
}
if( $xml_current_tag_state == "DESCRIPTION" ) {
$property_data = $property_data.$data;
}
}
if( !($xml_parser = xml_parser_create()) )
die();
if(xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler")) ;
if(xml_set_character_data_handler($xml_parser, "characterDataHandler"));
xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler");
xml_set_character_data_handler($xml_parser, "characterDataHandler");
while( $data = fread($fp, 4096) )
{
if( !xml_parse($xml_parser, $data, feof($fp)) )
{
break;
}
}
xml_parser_free($xml_parser);
$start="SP";
$find="<a href="http://weather.yahoo.com/forecast/UKXX0047.html";
$pos1=strpos($property_data, $start);
$pos2=strpos($property_data, $find);
$pos1=$pos1+2;
$pos2=$pos2-38;
echo substr($property_data, $pos1, $pos2); 
?>
 
Looks like the lines that read
Code:
$xml_current_tag_state = ';
are missing a second single quote.

Change those lines to
Code:
$xml_current_tag_state = '';
and see how you get on :).
 
hmm managed to get that part to work... but one more question lol.

It displays as this...

hoo! Weather for Durham, UK
Current Conditions:
Partly Cloudy, 16 C

Forecast:
Wed - Mostly Cloudy. High: 18 Low: 11
Thu - AM Clouds/PM


How the hell do i get rid of 'hoo!' I cant find it anywhere on the code, nor the xml.

cheers :)
 
Change
Code:
$pos1=$pos1+2;
to
Code:
$pos1=$pos1+7;
It's the hoo! of Yahoo!
Code:
<description>Yahoo! Weather for Durham, UK</description>
 
You may also want to change this
Code:
$find="<a href="http://weather.yahoo.com/forecast/UKXX0047.html";
To this:
Code:
$find="<a href=\"http://weather.yahoo.com/forecast/UKXX0047.html";

Otherwise, PHP thinks you're ending the string literal with the quotation marks in href="...
 
if( $element_name == "CHANNEL" ) {
function
characterDataHandler( $parser , $data )

editted :)

editted again because I'm stupid :)
 
Last edited:
thing is.. it's the most simple change EVAR..
Code:
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">$vbphrase[php_code]:</div>
	<div class="alt2" style="margin:0px; padding:$stylevar[cellpadding]px; border:1px inset; width:$stylevar[codeblockwidth]; height:{$blockheight}px; overflow:auto">
		<code style="white-space:nowrap">
		<div dir="ltr" style="text-align:left;background:#fff;">
			<!-- php buffer start -->$code<!-- php buffer end -->
		</div>
		</code>
	</div>
</div>

save that in vBulletin's bbcode_php template and voila.. white background.
 
robmiller said:
Just install the greasemonkey script I wrote that makes it white :)

http://pwnt.co.uk/uploads/files/1/ocukphp.user.js

ooh thanks. that blue background is totally ridiculous - i end up having to highlight everything just to make it readable anyway!!! i've not used greasemonkey before - i take it scripts are easy to install

edit: actually, don't you have something for this that makes the whole forum white?
 
Back
Top Bottom