Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Mar 2005
    Posts
    3
    Member #
    9365
    Hi!

    I'm a complete newbee to PHP. PHP-lamer?
    I want to extract some text from a webpage.

    (http://www.webdesignforums.net/showthread.php?t=10555 AND http://www.webdesignforums.net/showthread.php?t=10661)

    I'v been looking at the post mentioned above and realize that I will not be able to modify the code to suit my purpose.

    I'm don't know the syntax or synopsis for PHP and it was ages since I did any serious programing (Assembler for the Motorola 680xx, ARexx (Amiga))

    Does anyone think they can help me write these lines?

    Thank you!

    The adress to the page is: http://www.aro.lfv.se/metais/MetInfo...n&Frequency=30

    The text I want to extract on this page and it printed on my page is the line starting with "ESSV" and ending with "="

    /Mattias

  2.  

  3. #2
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    137 times
    Just this?
    ESSV 192320Z 35012KT 9999 FEW030 M03/M08 Q1028=

    Will this be used on other pages, and will they always scrape only info between ESSV and =?
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  4. #3
    Junior Member
    Join Date
    Mar 2005
    Posts
    3
    Member #
    9365
    Quote Originally Posted by Wired
    Just this?
    ESSV 192320Z 35012KT 9999 FEW030 M03/M08 Q1028=

    Will this be used on other pages, and will they always scrape only info between ESSV and =?
    Just this:
    ESSV 192320Z 35012KT 9999 FEW030 M03/M08 Q1028=


    It should include the "ESSV" & "=" to

    Same page always, I told U, I'm a PHP lamer

  5. #4
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    As you have a distinct identifier in the generated HTML, you can use ESSV as a lighthouse for the RegEx search. The ending double slashes and the 'equals' mark are dropped as well.

    The RegEx becomes very simple:

    __________


    Beeing a pilots question:

    Här är Visby koden
    (från en norsk SAS pilot)
    PHP Code:
    <html> 
    <head> 
    <title>METAR extractor</title> 
    </head> 

    <body> 
    <?php 
        $url 
    "http://www.aro.lfv.se/metais/MetInfo.asp?TextFile=metar.sweden.list.txt&SubTitle=&T=METAR%A0Sweden&Frequency=30"
        @
    $fp fopen($url,"r"); 
        if(
    $fp
           { 
            while(!
    feof($fp)){ 
                
    $buffer fgets($fp600); 
                @
    $file .= $buffer
           } 
        
    fclose($fp); 
        } else { 
            die(
    "<h2>Could not create a connection to METAR Sweden</h2>");     
        } 
    ?> 
    <?php 
         
        preg_match
    ("/ESSV\s+(.*)\/\/=/i"$file$WX);
        echo 
    "<b>ESSV: </b> $WX[1]";         
    ?> 
    </body> 
    </html>
    S. Rosland

  6. #5
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    137 times
    Does the info ever change?
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  7. #6
    Junior Member
    Join Date
    Mar 2005
    Posts
    3
    Member #
    9365
    Quote Originally Posted by rosland
    As you have a distinct identifier in the generated HTML, you can use ESSV as a lighthouse for the RegEx search. The ending double slashes and the 'equals' mark are dropped as well.

    The RegEx becomes very simple:

    __________


    Beeing a pilots question:

    Här är Visby koden
    (från en norsk SAS pilot)
    PHP Code:
    <html> 
    <head> 
    <title>METAR extractor</title> 
    </head> 

    <body> 
    <?php 
        $url 
    "http://www.aro.lfv.se/metais/MetInfo.asp?TextFile=metar.sweden.list.txt&SubTitle=&T=METAR%A0Sweden&Frequency=30"
        @
    $fp fopen($url,"r"); 
        if(
    $fp
           { 
            while(!
    feof($fp)){ 
                
    $buffer fgets($fp600); 
                @
    $file .= $buffer
           } 
        
    fclose($fp); 
        } else { 
            die(
    "<h2>Could not create a connection to METAR Sweden</h2>");     
        } 
    ?> 
    <?php 
         
        preg_match
    ("/ESSV\s+(.*)\/\/=/i"$file$WX);
        echo 
    "<b>ESSV: </b> $WX[1]";         
    ?> 
    </body> 
    </html>
    :-D

    Thank you!

    Will implement this to my phpBB after work!

    (Jag har flugigt segelflyg på Notodden för snart 20 år sedan (ASK21))

  8. #7
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Quote Originally Posted by Wired
    Does the info ever change?
    Yes, it changes every 30 minutes. It's the weather observation and immediate forecast for an airfield named "Visby" in Sweden. It's written in a simple abbreviated METAR code. The longer forecast TAF (Terminal Area Forecast) follows much the same code.

    Short example:
    210920Z VRB01KT 9999 M14/M16 Q1016 RESN TEMP 0500 +SHSN VV002
    Means:
    Observation made on the 21th at 0920 Zulu time .Wind variable less than 1 Kts, visibility more than 10 kilometers, temperature minus 14 deg Celsius, dew point minus 16 deg C, airpressure (QNH) 1016 HPa (HectoPascal). Recent snow, temporary horizontal reduction in visibilty to 500 meters in heavy snow showers, vertical visibility 200 feet.
    S. Rosland

  9. #8
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    137 times
    Quote Originally Posted by rosland
    temperature minus 14 deg Celsius
    BRRRR.......
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:08 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com