1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP error.

Discussion in 'HTML, Graphics & Programming' started by hybrid, 7 Jun 2006.

  1. hybrid

    Wise Guy

    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); 
    ?>
     
  2. Augmented

    Soldato

    Joined: 18 Oct 2002

    Posts: 5,464

    Location: London Town

    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 :).
     
  3. hybrid

    Wise Guy

    Joined: 18 Nov 2003

    Posts: 1,311

    Location: Newcastle

    Excellent mate, thanks very much. :)

    Quick response too :D
     
  4. hybrid

    Wise Guy

    Joined: 18 Nov 2003

    Posts: 1,311

    Location: Newcastle

    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 :)
     
  5. Augmented

    Soldato

    Joined: 18 Oct 2002

    Posts: 5,464

    Location: London Town

    Change
    Code:
    $pos1=$pos1+2;
    to
    Code:
    $pos1=$pos1+7;
    It's the hoo! of Yahoo!
    Code:
    <description>Yahoo! Weather for Durham, UK</description>
     
  6. Inquisitor

    Capodecina

    Joined: 12 Apr 2004

    Posts: 11,788

    Location: Somewhere

    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="...
     
  7. Dj_Jestar

    Caporegime

    Joined: 18 Oct 2002

    Posts: 29,213

    Location: Back in East London

    Honestly, why won't someone just simply change the background of the php div?
     
  8. hybrid

    Wise Guy

    Joined: 18 Nov 2003

    Posts: 1,311

    Location: Newcastle

    Thanks very much, that should be sorted now.

    Cheers peeps. :D
     
  9. Inquisitor

    Capodecina

    Joined: 12 Apr 2004

    Posts: 11,788

    Location: Somewhere

    I've alwas wondered that... it's almost useless as it is :/
     
  10. robmiller

    Capodecina

    Joined: 26 Dec 2003

    Posts: 16,522

    Location: London

  11. Inquisitor

    Capodecina

    Joined: 12 Apr 2004

    Posts: 11,788

    Location: Somewhere

  12. yhack

    Mobster

    Joined: 6 Jan 2005

    Posts: 3,632

    Location: Cambridge

    if( $element_name == "CHANNEL" ) {
    function
    characterDataHandler( $parser , $data )

    editted :)

    editted again because I'm stupid :)
     
    Last edited: 7 Jun 2006
  13. Dj_Jestar

    Caporegime

    Joined: 18 Oct 2002

    Posts: 29,213

    Location: Back in East London

    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.
     
  14. robmiller

    Capodecina

    Joined: 26 Dec 2003

    Posts: 16,522

    Location: London

    Pretty sure that the admins have said no before on the grounds that it was "hacking the forums".
     
  15. Sic

    Capodecina

    Joined: 9 Nov 2004

    Posts: 15,365

    Location: SO16

    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?
     
  16. Dj_Jestar

    Caporegime

    Joined: 18 Oct 2002

    Posts: 29,213

    Location: Back in East London

    and now that I am back at work I have remembered I can't use FF here.. haven't checked, does GM work with IE?
     
  17. Augmented

    Soldato

    Joined: 18 Oct 2002

    Posts: 5,464

    Location: London Town

    No.
     
  18. robmiller

    Capodecina

    Joined: 26 Dec 2003

    Posts: 16,522

    Location: London


    http://forums.overclockers.co.uk/showthread.php?t=17569431