replace symbol by space

Asked

Viewed 169 times

0

I need to replace the signal + for %20

Example : São+Paulo for Are%20Paulo

the search is on Laravel with knockout

  • Utilize str_replace

  • Have you seen that?

  • used and didn’t work, see part of the code { $encoded = urldecode($query); }

  • I could improve on the question with some extra explanation. Where does Knockout come into it?

  • @Toninho if possible post the code you made and it didn’t work.

  • posted in a new answer

  • If it’s just the +sign, I recommend using a str_replace, but if you want to replace characters and leave only the letters, then I advise you to use the preg_replace

Show 2 more comments

1 answer

0

Dbsearch

public function byQuery($query)
    {
        return \Title::whereTitleLike(preg_replace("/[ -:\'\"]/i", '%', $query))->orderBy('created_at','desc')->get();
    }
}

Blade

controller

original

{
            $encoded = $query;
        }
        else
        {
            $encoded = urlencode($query);
        }

modified

public function byQuery()
    {       
        $query = (string) Input::get('genre');

        if ( ! $query || Str::length($query) <= 1)
            return View::make('Search.Results')->withTerm('');

        //don't encode the query if we will search our db as that will
        //cause problems
        if ( is_a($this->search, 'Lib\Services\Search\DbSearch') )
        {
            $encoded = urldecode($query);
        }
        else
        {
            $encoded = urldecode($query);
        }

        if ( ! Cache::tags('search')->has($this->provider.'search'.$encoded))
        {
            $results = $this->search->byQuery($encoded);
            Cache::tags('search')->put($this->provider.'search'.$encoded, $results, 8640);
        }
        else
        {
            $results = Cache::tags('search')->get($this->provider.'search'.$encoded);   
        }

        return View::make('Search.Results')->withData($results)->withTerm(e($query));
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.