Jump to content

how 2 use file xxx.txt, row by row as input for php function


Recommended Posts

Hi folks,

I have a neat function that does WHOPPHIE with a given url.
I also have a text file [urls.txt] that consists of urls, each in a single line, that I want to be WHOOPIED.

Hmmm - now how do I do that?


Any help would be very much appreciated.
Dennis
Never head of WHOOPHIE before. What is it? Also provide more information too about what you are trying along with a visual referencce too. PLus could you provide an example what is in urls.txt
OK then,

The text file xxx.txt looks like:

[nobbc]http://www.yahoo.com
http://www.google.com
http://www.thisismysite.com
...
...[/nobbc]
and so on


the code I have up to now accepts any one of these urls in a dialog box on a page called index.php in a form and gives this url to a php script like the one below.

The script stores whatever it has done in a database.

What I want is that the php script below accepts the text file directly as input and works on it line for line.

CODE:
<?

$content = $_POST; // ************* Here come the url from a dialog box one page before...
$content = file_get_contents($content['url']);

// ******************************** Now a lot of stuff (WHOOPHIE) is done to that file...

// BEZEICHNUNG
preg_match("=<h1[^>]*>(.*)</h1>=siU", $content, $hit);
$data['obj_bez'] = trim($hit[1]);

// KURZTEXT
preg_match("=<h2[^>]*>(.*)</h2>=siU", $content, $hit);
$data['obj_krz'] = trim($hit[1]);

...
...
...

// ******************************* and store array (WHOOPHIE) in a database...


$insert_data = array(
  'obj_bez'=> $data['obj_bez'],
  'obj_krz'=> $data['obj_krz']
);
DB_Sql::query(DB_Sql::insert('objekte', $insert_data));
$insert_id = mysql_insert_id();
if(DB_Sql::error()) {
    echo DB_Sql::error();
    exit;
    }


?>
Not sure but prehaps:
[code]$contents = $_POST; // ************* Here come the url from a dialog box one page before...
$contents = file_get_contents($contents['url']);

$contents = str_replace(array("\r\n", "\r", "\n"), "\n", $contents);

$contents = explode("\n", $contents);

foreach($contents as $url)
{
    // ******************************** Now a lot of stuff (WHOOPHIE) is done to that file...

    // BEZEICHNUNG
    preg_match("=<h1[^>]*>(.*)</h1>=siU", $url, $hit);
    $data['obj_bez'] = trim($hit[1]);

    // KURZTEXT
    preg_match("=<h2[^>]*>(.*)</h2>=siU", $url, $hit);
    $data['obj_krz'] = trim($hit[1]);


    // ******************************* and store array (WHOOPHIE) in a database...


    $insert_data = array( 'obj_bez'=> $data['obj_bez'],
                          'obj_krz'=> $data['obj_krz']
                        );

    DB_Sql::query(DB_Sql::insert('objekte', $insert_data));

    $insert_id = mysql_insert_id();

    if(DB_Sql::error())
    {
        echo DB_Sql::error();
        exit;
    }
}[/code]
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.