Re: transfer list in textarea to comma delimited string
| From: | afan pasalic | Date: | Fri, 02 May 2008 15:43:09 +0000 |
| Subject: | Re: transfer list in textarea to comma delimited string | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-273806@lists.php.net to get a copy of this message | ||
Stut wrote:
> 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
>
works like a charm!
:D
thanks stut!
-afan