Jump to content

Jellz

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Jellz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. finished a script earlier today that scans a table in a db and extracts the email address from it, which is then exported to a csv file. now im combining the second half of the script except this time the information is coming from a csv, then performing the same operations and exporting the email address to a different csv. Problem is that the imported csv has csv line break codes placed in ( "\n"). WHen i open the exported file i see weird line breaks in excel and quotes ("") in notepad. str_replace doesn't seem to remove them. Here is the code. Any thoughts? <html> <head> <title>Data Manipulation</title> </head> <body> <h2>Email Address Extract</h2> <?php $valid_Emails=array(); $findme = '@'; $line_break = "\n"; $handle = @fopen("./import.csv", "r+"); if ($handle) { while (!feof($handle)) { $address = fgets($handle); $words= explode(' ', $address); foreach ($words as $value) { if(strpos($value,$findme) === false) { } else { array_push($valid_Emails, $value); } } } } $export = fopen("./export.csv", "w+"); fputcsv($export, $valid_Emails, $line_break); fclose($handle); fclose($export); ?> <text>Results have been saved to export.csv</text><br /> <input type=button onClick="location.href='./export.csv'" value='Download'> </body> </html>
  2. Finally got it. Thanks for all the suggestions <?php $result = mysql_query("SELECT email FROM users"); $valid_Emails=array(); $findme = '@'; while($row = mysql_fetch_array($result)) { $address = (string)$row['email']; $words=array(explode(' ', $address)); foreach ($words as $value) { $numofrows = count($value); for ($i = 0; $i < $numofrows; $i++) { if(strpos($value[$i],$findme) === false) { } else { echo "@ was found in " . $value[$i] . "<br />"; array_push($valid_Emails, $value[$i]); } } } } $csv_file = implode(",", $valid_Emails); ?>
  3. Thanks for the suggestions but neither of those ended up doing quite what I'm looking for. I've made some modifications and think I am fairly close so I'll get really specific with where I'm at and see if anyone has any helpful suggestions. Here is the PHP piece of my code. I use the include function to store the connection to my database so just assume that's done correctly (b/c it is). I think the real problem is if I am using the foreach function properly, as well as if attempting to search for the "@" symbol using the == operator. My comments are highlighted in orange so you can at least see my thought process. I've been plugging at this for hours and just can't QUITE get it. Ideas appreciated. <?php //convert email column to string $result = mysql_query("SELECT email FROM users"); //create please array to store valid email addresses $please=array(); $findme = "@"; //for each row of 'email' in table 'users' while($row = mysql_fetch_array($result)) { $address = (string)$row['email']; //take the entire string and explode each word into array $words using the ' ' as a delimiter $words=array(explode(' ', $address)); //loop over $words applying its value to $value foreach($words as $value) { //if the $value has $findme (the @) if($value == "$findme"){ //echo $value and push it to $please array echo "I have a @ in my string! <br />"; array_push($please, "$value); }else{ echo "Doesnt have @ in string! <br />" unset($value); } } ?>
  4. Im fairly new to PHP, been reading for some time and copying things from books, but am just now trying to develop my own app. I'm looking to take a line from my mySql database, see if there is an email address, and if so to save that. Some lines may have extra stuff in them like "hello bob [email protected] how are you". My thought was to store each row as a string, then to explode that string into an array based off the " " (space). Then to test to see if a member of an array had the "@", if so to store that into another array, if not, to spit out "No Email address found". Here is where I'm at. Any suggestions would be appreciated. <html> <head> <title>Data Manipulation</title> <?php include 'header.php'; ?> </head> <body> <h2>Email Address Extract</h2> <?php //convert email column to string $result = mysql_query("SELECT email FROM users"); //array to store strings with @ $please=array(); while($row = mysql_fetch_array($result)) { $address = (string)$row['email']; $findme = '@'; $test1 =(explode(" ",$address)); $pos = strpos($test1, $findme); if($pos === false) { echo "No email address found<br />"; } else { array_push($please,"$test1"); } print_r ($please); } ?> </body> </html>
×
×
  • 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.