dfrojd Posted September 4, 2006 Share Posted September 4, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/19659-how-2-use-file-xxxtxt-row-by-row-as-input-for-php-function/ Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/19659-how-2-use-file-xxxtxt-row-by-row-as-input-for-php-function/#findComment-85655 Share on other sites More sharing options...
dfrojd Posted September 4, 2006 Author Share Posted September 4, 2006 OK then,The text file xxx.txt looks like:[nobbc]http://www.yahoo.comhttp://www.google.comhttp://www.thisismysite.com......[/nobbc]and so onthe 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...// BEZEICHNUNGpreg_match("=<h1[^>]*>(.*)</h1>=siU", $content, $hit);$data['obj_bez'] = trim($hit[1]);// KURZTEXTpreg_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; }?> Quote Link to comment https://forums.phpfreaks.com/topic/19659-how-2-use-file-xxxtxt-row-by-row-as-input-for-php-function/#findComment-85661 Share on other sites More sharing options...
Jenk Posted September 4, 2006 Share Posted September 4, 2006 use file() and foreach()[code]<?phpforeach (file('urls.txt') as $line) { WHOPPHIE($line); //whatever 'WHOPPHIE' does..}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19659-how-2-use-file-xxxtxt-row-by-row-as-input-for-php-function/#findComment-85662 Share on other sites More sharing options...
dfrojd Posted September 4, 2006 Author Share Posted September 4, 2006 Hey, great, THANX!I´ll get to work and try that.Dennis Quote Link to comment https://forums.phpfreaks.com/topic/19659-how-2-use-file-xxxtxt-row-by-row-as-input-for-php-function/#findComment-85665 Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/19659-how-2-use-file-xxxtxt-row-by-row-as-input-for-php-function/#findComment-85667 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.