I got this code that will :
- Ask user to upload
.docxwhich contains format like this (erina,natasha culler,danial joshstone) - After they upload the list name will be inserted to the database. Every name got teir own row in database.
The code below is running well. But after the name is inserted, the database becomes like this:

If you see the first name erina, you can see that it got a big space. But rest of the names were inserted perfectly. It's just for the first one. I dont know why. Because of that space I cant search query the erina name. I tried many things, but still got that result.
<?php
include 'configure.php';
if(isset($_FILES['uploaded_file']))
{
$document_path = $_FILES ['uploaded_file']['tmp_name'];
$document_name=$_FILES ['uploaded_file']['name'];
function extracttext($filename,$filepath)
{
$ext = explode('.', $filename);
$ext=end ($ext);
if($ext == 'docx')
$dataFile = "word/document.xml";
else
$dataFile = "content.xml";
$zip = new ZipArchive;
if (true === $zip->open($filepath))
{
if (($index = $zip->locateName($dataFile)) !== false)
{
$text = $zip->getFromIndex($index);
$xml = new DOMDocument;
$xml->loadXML($text, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
return strip_tags($xml->saveXML());
}
$zip->close();
}
return "File not found";
}
$friendslist = extracttext($document_name,$document_path);
$id = "24";
$friendarray = explode(",", $friendslist);
$frienduserarray = array();
for ($n = 0; $n < count($friendarray); $n++)
{
$friendidpush = "('".$id."','".$friendarray[$n]."'),";
array_push($frienduserarray, $friendidpush);
}
$query = "INSERT INTO keywords (criteria, value) VALUES ";
$friendarray = explode(",", $friendslist);
foreach ($friendarray as $friend)
{
$query .= "('" . $id . "','" . $friend . "'),";
}
$query = substr($query, 0, -1); // remove trailing comma
mysql_query($query);
}
?>
How to fix this problem?
$friendarray = explode(",", $friendslist);:$friendarray = array_map('trim', $friendarray);.