Jump to content

Help me in combining two parts of my 20 liner: file_get_contents: & parsing


dilbertone

Recommended Posts

hello dear community, good day

 

 

i have  a problem -  a parser that does not parse. IT does not work! It gives not back anything!

 

 

 

<?PHP // Original PHP code by Chirp Internet: http://www.chirp.com.au
// Please acknowledge use of this code by including this header.

$url = "http://www.edi.admin.ch/esv/00475/00698/index.html?lang=de";

//$input = @file_get_contents($url) or die("Could not access file: $url");

$input = file_get_contents($url) or die("Could not access file: $url"); 

$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER)) { foreach($matches as $match) {

// $match[2] = all the data i want to collect...
// $match[3] = text that i need to collect - see a detail-page

}
} ?>

 

 

well - it goes a bit over my head:  "what - i have did" - it does not give back any results!?

 

 

i look forward to hear from you!

 

regards

Link to comment
Share on other sites

hi gizmola hello xyph

 

thanks for answering! i am happy!

 

That code snippet does not output anything via var_dump() or echo.

 

many many thanks.- That means i  have to rewrite this part!? - gizmola - i am a newbie; I  will try it. But perhaps you can help me!?

 

Update; i  will definitly try this one: print_r($matches) to see what's going on

 

lookforward  - best regards

martin

Link to comment
Share on other sites

hello dear friends this code

 

 

first of all:  a big big SORRY for being the Newbie -

 

 

 

@gizmola: i did the changes:

 

Did you try what xyph suggested.  Being a noobie does not excuse one from actually doing some reading and learning.  There is nothing more basic than output... print_r(), echo(), var_dump(), die().  You need to read about these in the php manual, not to mention the functions in the code you are using.

 

well i guess that i did the changes... but i had no luck...  look and see - this is so mystic! i do not know whats going one here:

 

<?PHP 

// Original PHP code by Chirp Internet: http://www.chirp.com.au
// Please acknowledge use of this code by including this header.

$url = "http://www.edi.admin.ch/esv/00475/00698/index.html?lang=de";

//$input = @file_get_contents($url) or die("Could not access file: $url");

$input = file_get_contents($url) or die("Could not access file: $url"); 

$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER)) { foreach($matches as $match) {

// $match[2] = all the data i want to collect...
// $match[3] = text that i need to collect - see a detail-page

print_r($matches) 

}
}

?>

 

 

gives back

 

 

martin@suse-linux:~/perl/foundations> php fondations_de.php

PHP Parse error:  syntax error, unexpected '}' in /home/martin/perl/foundations/fondations_de.php on line 20

martin@suse-linux:~/perl/foundations> ^C

martin@suse-linux:~/perl/foundations>

 

 

 

Link to comment
Share on other sites

hello gitzmola - many many thanks i will have a look!

 

on a sidenote: - and i also want to look if the parser-part runs ...

Guess the part that FETCHES the data is not so complicated as the part that parses the data...

 

 

anyway - many many  thanks for any and alll help! i come back and report all my findings!!

 

greetings

db1

 

UPDATE:  - HELLO DEAR FRIENDS: -this gives back something very very intersting. ...

 

well see: (i have postet only a part.... the whole stuff is tooo  big to post here.... )

But wait: what can i do!?

 

note - i want to get all the data out of this database:  http://www.edi.admin.ch/esv/00475/00698/index.html?lang=de

 

 

At the moment we have these results:

 

how to  proceed: ?!

 

 

    [16] => Array

        (

            [0] => <a href="/esv/index/index.html?lang=de" title="Zum Schlagwort-Index" class="webServiceContent" accesskey="6">Index</a>

            [1] => "

            [2] => /esv/index/index.html?lang=de

            [3] => Index

        )

 

    [17] => Array

        (

            [0] => <a href="/esv/printtool/index.html?lang=de" title="Printtool" class="webServiceContent">Printtool</a>

            [1] => "

            [2] => /esv/printtool/index.html?lang=de

            [3] => Printtool

        )

 

    [18] => Array

        (

            [0] => <a href="/hinweise/index.html?lang=de" title="Zu den Bedienungshinweisen" class="webServiceContent">Hilfe</a>

            [1] => "

            [2] => /hinweise/index.html?lang=de

            [3] => Hilfe

        )

 

    [19] => Array

        (

            [0] => <a href="/esv/00475/00698/index.html?lang=de" class="webSpracheAktiv" title="Diese Seite auf deutsch">Deutsch</a>

            [1] => "

            [2] => /esv/00475/00698/index.html?lang=de

            [3] => Deutsch

        )

 

    [20] => Array

        (

            [0] => <a href="/esv/00475/00698/index.html?lang=fr" class="webSpracheInaktiv" title="Cette page en fran�ais">Fran�ais</a>

            [1] => "

            [2] => /esv/00475/00698/index.html?lang=fr

            [3] => Fran�ais

        )

 

.....and so forth and so forth!! ...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.