Reply to Re: [PHP] Replacing spaces with commas

Your name:

Reply:


Posted by trlists on 04/17/05 16:09

On 17 Apr 2005 W Luke wrote:

> I have about 200 records in a table, and I need to update 2 of the
> fields. The first is easy, but the second contains a list of keywords
> all separated by spaces; I need to replace the spaces with commas. Is
> this something I can do with some clever SQL, or shall I just do it in
> PHP?

Well I have not used this function, but it looks like it would do what
you want (this is from MySQL):

REPLACE(str,from_str,to_str)

Returns the string str with all all occurrences of the string
from_str replaced by the string to_str

So for example:

REPLACE(field, ' ', ',');

In other words, how about a query like this:

UPDATE table SET field=REPLACE(field, ' ', ',');

I have not tried using a function in an UPDATE statement like this but
you can test it and see, I would expect it to work.

In PHP you can do the same thing -- load the data with the mysql_
functions, then:

$newval = str_replace(' ', ',', $oldval);

then use UPDATE to put $newval back into the database.

--
Tom

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация