Results 1 to 1 of 1

Thread: How To Import Lists Of Cut And Paste Webpage Data To PHP

  1. #1
    Andy101's Avatar
    Andy101 is offline Code Otaku
    Join Date
    Aug 2009
    Location
    Kanazawa
    Posts
    1,314
    Thanks
    178
    Thanked 309 Times in 236 Posts

    How To Import Lists Of Cut And Paste Webpage Data To PHP

    Say you do a search on something that produces a web page listing things such as a top 100 list of hit singles.

    You can select the content of the page by dragging your mouse over the area, and then CTRL->C CTRL-V to a spread sheet. I use Open Office (calc).

    Then, if you are lucky, the spreadsheet will automatically separate the data into convenient columns.

    Then delete the columns of content you don't want and save the spreadsheet as CSV format but as say data.txt

    Then in PHP, you can write a simple script to read the text file and parse the data to SQL or PHP array code such as:

    PHP Code:
    <pre>
    <?php
    $menData 
    file_get_contents('men.txt');
    $womenData file_get_contents('female.txt');
    $surnameData file_get_contents('surnames.txt');

    $m explode("\r\n"$menData);
    $fexplode("\r\n"$womenData);
    $s explode("\r\n"$surnameData);

    $a "\$m = array (\n";
    foreach(
    $m as $n$a .= "\t'" ucfirst(strtolower(trim($n'"'))) . "',\n";
    $a .= ");\n";

    $a .= "\n\$f = array (\n";
    foreach(
    $f as $n$a .= "\t'" ucfirst(strtolower(trim($n'"'))) . "',\n";
    $a .= ");\n";

    $a .= "\n\$s = array (\n";
    foreach(
    $s as $n$a .= "\t'" ucfirst(strtolower(trim($n'"'))) . "',\n";
    $a .= ");\n";

    file_put_contents('names.tmp'$a);
    ?>
    OK
    This is just an example of code I used to produce a list of people's names on the windows platform (hence the carriage return, line break nonsense). The output file: names.tmp contained some PHP code that I cut and pasted into the actual script that I was writing.

    So this is a way to save you a huge amount of manual effort when compiling data from the web to use in a database or web app.

    For fun, you can try the random name generator that I came up with here: Name Generator Press F5 on your keyboard to generate a new name.
    Last edited by Andy101; 29 January, 2011 at 15:46 PM. Reason: Added a link to my random name generator script
    Otaku CMS - Import a WordPress blog and manage your site using single-page App technology
    Angular Skills - new site about Front-end App. programming

Similar Threads

  1. Problem to Import E-mail
    By blasir in forum PHPAutoresponder Support
    Replies: 1
    Last Post: 25 March, 2011, 18:27 PM
  2. How to import database to Wordpress?
    By thesyndicate in forum Wordpress
    Replies: 6
    Last Post: 12 April, 2010, 23:15 PM
  3. where i should paste this code?
    By garfish in forum Programming
    Replies: 4
    Last Post: 9 April, 2010, 08:39 AM
  4. [WTS] Paste-It script just for 15$
    By chetan in forum Scripts
    Replies: 6
    Last Post: 26 September, 2009, 16:34 PM
  5. [Free] Low rate copy paste forum posting services
    By badmash in forum Services
    Replies: 0
    Last Post: 12 September, 2009, 08:25 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •