Hi,

New to PHP, wondered if anyone could point me to a script that would do the following:

get email address from a website.

Basically there is a site that is open for public viewing with addresses and phone numbers and email addresses that my client would like to target.

to save a temp sitting typing through this register into excel is there a tool or script that can be run to get the data and download into an excel sheet, or xml file?

many thanks

Are u saving data in database or not , if u r saving data in database then there is complete script that get values from database and make excel file and export it to the user.
make a file name

exportcsv.php

and write the following code

if(isset($_GET['type']) && $_GET['type'] !=""){

    if($_GET['type'] =="tablename")
        $table="tablename";
} 
$filename = date('Y-m-d',time())."_Exportcsv.csv";
exportMysqlToCsv($table,$filename);

now the function do the rest that-is

function exportMysqlToCsv($table,$filename = 'export.csv')
{
    $csv_terminated = "\n";
    $csv_separator = ",";
    $csv_enclosed = '"';
    $csv_escaped = "\\";

if($table == 'tablename')
{
 $sql_query = "select field1 as 'Field1 alis',field2 as 'field2 ales' from $table";
}

// Gets the data from the database
    //  $result = mysql_query("comment_By as 'Name',comment_Phone as 'Phone Number',comment_Data as 'Comments',comment_Email as 'Email',comment_Date as 'TimeStamp' FROM ".$sql_query."");

    $result = mysql_query($sql_query);

    $fields_cnt = mysql_num_fields($result);

    $schema_insert = '';

    for ($i = 0; $i < $fields_cnt; $i++)
    {
        $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;

        $schema_insert .= $l;
        $schema_insert .= $csv_separator;
    } // end for
    $out = trim(substr($schema_insert, 0, -1));
    $out .= $csv_terminated;
    // Format the data
    while ($row = mysql_fetch_array($result))
    {
        $schema_insert = '';
        for ($j = 0; $j < $fields_cnt; $j++)
        {
            if ($row[$j] == '0' || $row[$j] != '')
            {
                if ($csv_enclosed == '')
                {
                    $schema_insert .= $row[$j];
                } else
                {
                    $schema_insert .= $csv_enclosed .
                    str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes($row[$j])) . $csv_enclosed;
                }
            } else
            {
                $schema_insert .= '';
            }
            if ($j < $fields_cnt - 1)
            {
                $schema_insert .= $csv_separator;
            }
        } // end for
        $out .= $schema_insert;
        $out .= $csv_terminated;
    } // end while
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Length: " . strlen($out));
    // Output to browser with appropriate mime type, you choose ;)
    header("Content-type: text/x-csv");
    //header("Content-type: text/csv");
    //header("Content-type: application/csv");
    header("Content-Disposition: attachment; filename=$filename");
    echo $out;
    exit;
}

you can save this code to other file like functions.php

now only one thing remains to make call to the export.php file u can do the following from any where

<a href="exportcsv.php?type=table">Export CSV File</a>    

if u make function file then donot foget to include the function file in to exportcxv.php
require ("include/function.php");

s

It depends on how it's laid out. You don't sound as if you have any information on the database name or passwords, so you would have to scrape it. There are plenty of scripts to do this sort of thing.

Hi thanks for the replies, tiggsy you are correct i do not have this info. This is potential clients for my client to mailshot.

What sort of script would i need to do this?

many thanks

thanks for this, the site has no security it is an open site free to use the contact details from it for the public.

Just it would be a pain typing it all from the site into a spreadsheet manually so need something that can pull it down from there.

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.