Connecting Tech Pros Worldwide Help | Site Map

Replace a character in a string variable

 
LinkBack Thread Tools Search this Thread
  #1  
Old June 30th, 2006, 02:55 PM
Syl
Guest
 
Posts: n/a
Default Replace a character in a string variable

Hi group -

I have a variable which is created from an input form.
After concatenating the input I want, I end up with a variable named
$all which looks like this :
delegatecountry,delegatefname,delegatelname,delega tebname

I want to take this string and replace all the commas with this :
</th><th>

So - I tried this :

$inside="</th><th>";
$newall = str_replace($inside, ",", $all);


But - it doesn't work.
http://ca3.php.net/str_replace

What am I doing wrong ?


  #2  
Old June 30th, 2006, 02:55 PM
ED
Guest
 
Posts: n/a
Default Re: Replace a character in a string variable


"Syl" <david.hunter@gmail.com> wrote in message
news:1151679331.062036.128540@x69g2000cwx.googlegr oups.com...[color=blue]
> Hi group -
>
> I have a variable which is created from an input form.
> After concatenating the input I want, I end up with a variable named
> $all which looks like this :
> delegatecountry,delegatefname,delegatelname,delega tebname
>
> I want to take this string and replace all the commas with this :
> </th><th>
>
> So - I tried this :
>
> $inside="</th><th>";
> $newall = str_replace($inside, ",", $all);
>
>
> But - it doesn't work.
> http://ca3.php.net/str_replace
>
> What am I doing wrong ?
>[/color]

First 2 parameters the wrong way round, should be:

$newall = str_replace(',', $inside, $all);

cheers
ED


  #3  
Old June 30th, 2006, 03:05 PM
Syl
Guest
 
Posts: n/a
Default Re: Replace a character in a string variable


ED wrote:[color=blue]
> "Syl" <david.hunter@gmail.com> wrote in message
> news:1151679331.062036.128540@x69g2000cwx.googlegr oups.com...[color=green]
> > Hi group -
> >
> > I have a variable which is created from an input form.
> > After concatenating the input I want, I end up with a variable named
> > $all which looks like this :
> > delegatecountry,delegatefname,delegatelname,delega tebname
> >
> > I want to take this string and replace all the commas with this :
> > </th><th>
> >
> > So - I tried this :
> >
> > $inside="</th><th>";
> > $newall = str_replace($inside, ",", $all);
> >
> >
> > But - it doesn't work.
> > http://ca3.php.net/str_replace
> >
> > What am I doing wrong ?
> >[/color]
>
> First 2 parameters the wrong way round, should be:
>
> $newall = str_replace(',', $inside, $all);
>
> cheers
> ED[/color]

DOH!

Thanks very much ED for the quick reply!

  #4  
Old June 30th, 2006, 03:15 PM
ED
Guest
 
Posts: n/a
Default Re: Replace a character in a string variable


"Syl" <david.hunter@gmail.com> wrote in message
news:1151680198.937686.178460@p79g2000cwp.googlegr oups.com...[color=blue]
>
> ED wrote:[color=green]
>> "Syl" <david.hunter@gmail.com> wrote in message
>> news:1151679331.062036.128540@x69g2000cwx.googlegr oups.com...[color=darkred]
>> > Hi group -
>> >
>> > I have a variable which is created from an input form.
>> > After concatenating the input I want, I end up with a variable named
>> > $all which looks like this :
>> > delegatecountry,delegatefname,delegatelname,delega tebname
>> >
>> > I want to take this string and replace all the commas with this :
>> > </th><th>
>> >
>> > So - I tried this :
>> >
>> > $inside="</th><th>";
>> > $newall = str_replace($inside, ",", $all);
>> >
>> >
>> > But - it doesn't work.
>> > http://ca3.php.net/str_replace
>> >
>> > What am I doing wrong ?
>> >[/color]
>>
>> First 2 parameters the wrong way round, should be:
>>
>> $newall = str_replace(',', $inside, $all);
>>
>> cheers
>> ED[/color]
>
> DOH!
>
> Thanks very much ED for the quick reply!
>[/color]

:) no prob!


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.