I know this is the wrong type of forum, but know there are members here that code.
Just a quick question:
I'm trying to replace or remove wildcards in keywords but think I'm over complicating it (but being crap at pattern matching so a bit stumped).
I want to remove first and last %, and if there is no % add a space.
Example replacements:
'%keyword%' => 'keyword'
'keyword%' => ' keyword'
'%keyword' => 'keyword '
'keyword' => ' keyword '
This is the way I've done it, but is there a better way of doing it:
If anyone can think of a faster way of doing it I would be gratefulCode:$keyword = $keyword[0] != '%' ? ' ' . $keyword : substr($keyword, 1); $keyword = $keyword[strlen($keyword)-1] != '%' ? $keyword . ' ' : substr_replace($keyword, '', -1);![]()


LinkBack URL
About LinkBacks






Reply With Quote