I need to explode a string, first by line, and then by # and insert to mysql.
Like i have a string
Shahbaz#is my name
Singh#is my caste
I want the script to explode the string first by a new line, insert Shahbaz
into the word
column and is my name
into the note
column in mysql and same with Singh
and is my caste
.
include("connect.php");
$counter = 0;
$counters = 0;
$string = mysql_real_escape_string($_POST['words']);
$arr = explode(" ", $string);
mysql_query("SET charset utf8");
$sql = mysql_query("SELECT `word` FROM unicode WHERE word IN ('".implode("', '", $arr) . "')") or die (mysql_error());
$dupes = array();
while($r = mysql_fetch_assoc($sql)) {
$dupes[] = $r['word'];
}
$newwords = array_diff($arr, $dupes);
if(count($newwords)) {
$sqli = mysql_query("INSERT INTO unicode (word) VALUES ('" . implode("'),('", $newwords) . "')") or die (mysql_error());
}
In this script, it inserts each word, but doesnt insert the note column. It separates the words by a space. I want it to separate it by a new line and then insert the text after #
to the note
column...
Thanks in advance.