lilywong Posted April 27, 2006 Share Posted April 27, 2006 I have currently write an php page to import the data from .txt file and insert into mysql database.Data example in (test.txt file):[email protected][email protected]110007;"[email protected]"[email protected]the php page[code]<?$fd = fopen ("c:\test.txt", "r"); if (!$fd) { echo "ERROR: $errno - $errstr";} else { while ( !feof($fd) ) { $buffer = fgets($fd, 4096); <<i think i need to put checking here.... any ideas.. thanks...? $query = " INSERT INTO emailAddress(Email) values ($buffer)"; } fclose($fd); } ?> [/code]after in run the php script, the data will be insert into table and become:ID Email1 [email protected]2 [email protected]3 110007;"[email protected]"--> want this to be [email protected]4 [email protected]i want to remove the 110007; and the double quote, as i only want the take valid email address and save into my table. Is there any way to remove the 110007, ; , and "" so that the email address for ID 3 will become [email protected] ? Thanks Link to comment https://forums.phpfreaks.com/topic/8542-remove-special-charactars-before-insert-into-database/ Share on other sites More sharing options...
bbaker Posted April 27, 2006 Share Posted April 27, 2006 will other e-mails have the same [i]syntax[/i] as 110007;"[email protected]"? or could it be something different?if they will only have a syntax like the example the following function would work[code]function clean_email($email){ if (strstr($email, ';') == TRUE) { $email = split(';',$email); //splits string at; $email[0] will be '110007' $email[1] will be "[email protected]" $email = str_replace('"','',$email[1]); //removes " from $email[1] } return $email; // returns [email protected]}[/code]to use the function[code]$email = '110007;"[email protected]"';echo clean_email($email); //returns [email protected][/code] Link to comment https://forums.phpfreaks.com/topic/8542-remove-special-charactars-before-insert-into-database/#findComment-31305 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.