-1

I am importing a CSV file which contains list of URLS. These URLs are displaying in tabular format to perform some operations. But a space is added to the beginning of url. Because of this the operations I am performing on it fails. So how I can remove that space.When I done print_r() in my controller it shows result as �https://www.surveygizmo.com

if (($handle = fopen($filename, "r")) !== FALSE) 
{
    while (($value = fgetcsv($handle, 1000, ",")) !== FALSE) 
    {
         $num = count($value);

         for ($c=0; $c < $num; $c++) 
         {
               echo "<pre>";
               print_r($value[$c]);

Above a few lines of code. I am getting symbol,� before the content.

How can I remove that? I tried with trim. But still its not working. I need help. Thank you

  • what u have tried so far ,pls put some code there – Pradeep Apr 16 '18 at 09:56
  • 1
    I think that's UTF-8 BOM. Try [this](https://stackoverflow.com/a/15423899/9618184). – Binar Web Apr 16 '18 at 13:33
  • Thank you Binar Web for your support for beginners like me. The page which you linked helped me to resolve it. The final url after using that function gave '?' instead of space and then I trimmed '?'. Finally got the desired output. – Revathi Krishna K Apr 18 '18 at 04:25

1 Answers1

1

Try this. I have similar issue and after following tweak it fixed

$col_val = $value[$c];
$final_value = trim($col_val ," \t\n\r\0\x0B\"");
print_r($final_value);
Rejoanul Alam
  • 5,435
  • 3
  • 39
  • 68