Re: Split(), Explode()..
| From: | David Robley | Date: | Thu, 19 Oct 2000 04:28:55 +0000 |
| Subject: | Re: Split(), Explode().. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21072@lists.php.net to get a copy of this message | ||
On Thu, 19 Oct 2000, Maxim Maletsky wrote:
>
>
> Hello list,
> I have a simple (hopefully) question:
>
> I am trying to reformat the string by letters:
>
> $string = explode("", 'Hello World');
> echo implode (' ', $string);
>
> What I want is to separate each character of the string by whitespaces.
> Plus I want to keep the array ($string) for feature use.
>
> The code above gives me the following errors:
> Warning: Empty delimiter in /blah/blah.html on line 93
> Warning: Bad arguments to implode() in /blah/blah.html on line 94
>
> I also tried to use split:
>
> $string = split ("", 'Hello World');
> echo implode (' ', $string);
>
> and the errors received were:
> Warning: unexpected regex error (14) in /blah/blah.html on line 93
> Warning: Bad arguments to implode() in /blah/blah.html on line 94
>
> Anyone has an idea how to do it?
> Any function I don't know that does that?
>
> Can a loop help me? Regex? (BTW, the speed is pretty important)
>
> Thanks folks!
Well, a string variable is simply an array of characters, so you could just
loop through the variable and assign each element(letter) with a space
appended to it (unless it is already a space?) to a new variable.
Consider how you deal with the last element - ie does it need a space
appended?
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA