Pergunta

in a part of my website i have a url that looks like this:

http://www.webizzi.com/mp3/search.html?q=+Hush+Hush+-+(Avril)++Lavigne's+

I would like to keep a cleaner url by stripping every special character that appears on the url except + but i also do not want to have something like ++ or + at the beginning or end of the url, the url should look like the one below

http://www.webizzi.com/mp3/search.html?q=Hush+Hush+Avril+Lavigne

what i have to process the url at the moment is:

{$config.siteurl}search.html?q={$tags[row].tag|regex_replace:"/\s+/":"+"|stripslashes} 
Foi útil?

Solução

Assuming your input is everything after ?q=

s/(^\++|\++$|\+\++|[\(\)]+)//g

In those last pair of brackets, you put any other characters you want stripped.

This matches one or more opening +'s, one or more closing +'s, two or more +'s anywhere, or one or more the special characters inside the brackets (so far, just parentheses) and replaces it with nothing – an empty string – zilch – nada.


I don't know jack about Smarty, but I think you should try something like

{$config.siteurl}search.html?q={$tags[row].tag|regex_replace:"/(^\++|\++$|\+\++|[\(\)]+)/":""|stripslashes}

I'm not quite sure if you need to escape the parentheses here, so if it doesn't work, lose some backslashes.

Outras dicas

href="{$site_url}tests/tests/view/{$test.test_id}/{strtolower($test.test_name|replace:' ':'-'|regex_replace:'/(^++|++$|+++|[()]+)/':'')}">Test

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top