Re: [PHP] transfer list in textarea to comma delimited string
[email protected] (Stut)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
On 2 May 2008, at 16:22, afan pasalic wrote:
> I have one textarea field in a registration form where visitor enters
> keywords. even there is a not next to the field "please enter keywords
> as comma delimited string", they enter as a list, below each other.
>
> I tried to convert the list into comma delimited string with several
> solutions but non of them works:
> $keywords = eregi_replace('\n', '.', $keywords);
> $keywords = eregi_replace('\r', '.', $keywords);
> $keywords = eregi_replace('\n\r', '.', $keywords);
> $keywords = eregi_replace('<br>', '.', $keywords);
>
> any help here?
1) str_replace is more than capable of doing this in a single
statement - a regex is overkill.
2) You need to use double quotes around escape sequences (\n and \r)
or they'll be ignored.
$replacements = array("\r", "\n", "\n\r", '<br>');
$keywords = str_replace($replacements, '.', $keywords);
-Stut
--
http://stut.net/