You are here: Re: Splitting strings, explode? « All PHP « IT news, forums, messages
Re: Splitting strings, explode?

Posted by Stefan Rybacki on 08/27/05 15:02

mike wrote:
> "Stefan Rybacki" <stefan.rybacki@gmx.net> wrote in message
> news:3nasf0FmmgiU3@individual.net...
>
>>Well then you did something wrong while copy and paste. Try this code
>>snippet
>>
>>
>>$search = "Lisa, Marie, Jenny & Kevin";
>>
>>$names=explode(",",str_replace("&",",",$search));
>>
>>foreach($names as $name) {
>> $name=trim($name);
>>
>> print($name."\n<br>");
>>}
>>
>
>
> that's perfect, thanks guys!!
>
> It works just as I wanted, however. I'd kinda like to be able to understand
> what exactly the code is doing, which I don't really, especially this part:
>
> (",",str_replace("&",",",$search));
>
> the str_replace?

As the function name already suggests its about string replacement. This means before we
do the explode by comma we also have to replace all & characters in the search string with
a comma to get the correct result.


Stefan


PS: try this function for itself and see what happens:

print(str_replace("&",",","X, Y, Z & A"));

>
> regards
>
>

 

Navigation:

[Reply to this 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

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