-
preg_replace
I need to replace a space delimited string in a db query with apostrophy comma apostrophy.
I have this but it pukes.
PHP Code:
preg_replace('/ /', '', '', $myvar['keywords'])
Basically its ....
item1 item2 item3
And should be ...
item1', 'item2', 'item3
as I can easily wrap the external apostrophies around the result to make...
'item1', 'item2', 'item3'
What escape sequence do I need if any?
Thanks
-
Re: preg_replace
There is no need to use preg_replace. A simple str_replace will do it.
PHP Code:
$items_list = 'item1 item2 item3';
$items = "'".str_replace(' ', "', '", trim($items_list))."'";
-
Re: preg_replace
I have this now but its not matching any results.
PHP Code:
SELECT * FROM Table1
WHERE
(somefield = 1)
AND
(v.keywords IN('" . str_replace(' ', "', '", trim($myvar['keywords'])) . "'))
No errors but no results either. Could it be that the keywords field has a space delimited values in it? I just need to match any of those workds woith any that are in $myvar.