Re: [PHP] transfer list in textarea to comma delimited string

[email protected] (afan pasalic)
Newsgroups php.general
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.