Re: encode string with spaces
| From: | David Robley | Date: | Fri, 02 Feb 2001 01:23:14 +0000 |
| Subject: | Re: encode string with spaces | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-37768@lists.php.net to get a copy of this message | ||
On Fri, 2 Feb 2001 11:36, David Robley wrote:
> On Fri, 2 Feb 2001 11:22, Kevin McCarthy wrote:
> > All -
> >
> > Any easy way to take a string and fill the spaces in it? Say like a
> > URLencoding:
> >
> > This is my dog, Jack
> > becomes
> > This%20is%20my%20dog,%20Jack
> >
> > I ask this as I would like to send a string to a perl function that can
> > parse the string and create a hash from it based on delimiters I
> > define. But if there are spaces in the string in between defined
> > fields, it is thrown off.
> >
> > BTW, I tried both ereg_replace() and str_replace() with no luck as
> > below:
> >
> > $my_string = "This is my dog, Jack";
> > str_replace(" ", "%20", $my_string);
> >
> > $my_string remains with spaces, not %20s.
And that is because you need to do
$my_string = str_replace(" ", "%20", $my_string);
You have to assign the result of the function to something to see it :-)
--
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