Replace a character in a string variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Syl

    #1

    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,d elegatebname

    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($in side, ",", $all);


    But - it doesn't work.
    Replace all occurrences of the search string with the replacement string


    What am I doing wrong ?

  • ED

    #2
    Re: Replace a character in a string variable


    "Syl" <david.hunter@g mail.com> wrote in message
    news:1151679331 .062036.128540@ x69g2000cwx.goo glegroups.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,d elegatebname
    >
    > 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($in side, ",", $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


    Comment

    • Syl

      #3
      Re: Replace a character in a string variable


      ED wrote:[color=blue]
      > "Syl" <david.hunter@g mail.com> wrote in message
      > news:1151679331 .062036.128540@ x69g2000cwx.goo glegroups.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,d elegatebname
      > >
      > > 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($in side, ",", $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!

      Comment

      • ED

        #4
        Re: Replace a character in a string variable


        "Syl" <david.hunter@g mail.com> wrote in message
        news:1151680198 .937686.178460@ p79g2000cwp.goo glegroups.com.. .[color=blue]
        >
        > ED wrote:[color=green]
        >> "Syl" <david.hunter@g mail.com> wrote in message
        >> news:1151679331 .062036.128540@ x69g2000cwx.goo glegroups.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,d elegatebname
        >> >
        >> > 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($in side, ",", $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!


        Comment

        Working...