too long

I have prestashop. using IMPORTOSC module to inport data.

All works great , only issue the image which has space in it,s name as not imported to prestashop.(A space in URL)

Code for category import:

public function getCategories($limit = 0, $nrb_import = 100) {
        $multiLangFields = array('name', 'link_rewrite');
        $keyLanguage = 'id_lang';
        $identifier = 'id_category';

        $categories = $this->ExecuteS('
                                    SELECT c.categories_id as id_category, c.parent_id as id_parent, 0 as level_depth, cd.language_id as id_lang, cd.categories_name as name , 1 as active, categories_image as images
                                    FROM `'.bqSQL($this->prefix).'categories` c 
                                    LEFT JOIN `'.bqSQL($this->prefix).'categories_description` cd ON (c.categories_id = cd.categories_id)
                                    WHERE cd.categories_name IS NOT NULL AND cd.language_id IS NOT NULL
                                    ORDER BY c.categories_id, cd.language_id
                                    LIMIT '.(int)($limit).' , '.(int)$nrb_import);
        foreach($categories as& $cat)
        {
            $cat['link_rewrite'] = Tools::link_rewrite($cat['name']);
            $cat['images'] = array(Tools::getProtocol().Tools::getValue('shop_url').'/images/'.$cat['images']);
        }
        return $this->autoFormat($categories, $identifier, $keyLanguage, $multiLangFields);
    }

I searched and it looks like , it might be fixed by str_replace(' ', '%20', trim($url))

can someone help me with code.

Instead of str_replace(), use urlencode() (see the PHP manual for more details). The urlencode() function properly encodes all non-alpha characters besides "-" and "_".