str_replace

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

    #1

    str_replace

    Hello,

    Replacing the key : #0001# within $data doesn't work!! I want to replace it
    with a link!

    Any sugestions?

    Thanx,
    InSeCo

    *Example of the problem :*
    <?php
    $data = "abcdefghijklmn opqrstuvwxyz #0001# abcdefghijklmno pqrstuvwxyz<BR>
    \n";
    $data = $data."abcdefgh ijklmnopqrstuvw xyz abcdefghijklmno pqrstuvwxyz<BR>
    \n";
    $data = $data."abcdefgh ijklmnopqrstuvw xyz #0001#
    abcdefghijklmno pqrstuvwxyz<BR> \n";

    $repldata = "<A href=link.html> link</a>";
    $replold = "#0001#";
    echo "<B>Origina l Data</B><BR>$data;<HR >";
    echo "<B>Data to replace :</B> $replold <HR>";
    echo "<B>Replace data with :</B> $repldata <HR>";

    str_replace($re plold, $repldata , $data);
    echo "<B>New Data</B><BR>$data;<HR >";

    ?>


  • Kimmo Laine

    #2
    Re: str_replace

    "InSeCo" <InSeCo@news.ne ws> kirjoitti
    viestissä:425d2 f2a$0$142$e4fe5 14c@news.xs4all .nl...[color=blue]
    > Hello,
    >
    > Replacing the key : #0001# within $data doesn't work!! I want to replace
    > it
    > with a link!
    >
    > Any sugestions?
    >
    > Thanx,
    > InSeCo
    >
    > *Example of the problem :*
    > <?php
    > $data = "abcdefghijklmn opqrstuvwxyz #0001# abcdefghijklmno pqrstuvwxyz<BR>
    > \n";
    > $data = $data."abcdefgh ijklmnopqrstuvw xyz abcdefghijklmno pqrstuvwxyz<BR>
    > \n";
    > $data = $data."abcdefgh ijklmnopqrstuvw xyz #0001#
    > abcdefghijklmno pqrstuvwxyz<BR> \n";
    >
    > $repldata = "<A href=link.html> link</a>";
    > $replold = "#0001#";
    > echo "<B>Origina l Data</B><BR>$data;<HR >";
    > echo "<B>Data to replace :</B> $replold <HR>";
    > echo "<B>Replace data with :</B> $repldata <HR>";
    >[/color]
    $data = str_replace($re plold, $repldata , $data); // fix this[color=blue]
    > echo "<B>New Data</B><BR>$data;<HR >";
    >
    > ?>[/color]

    It doesn't perform the change on parameter given, instead it returns the
    changed string. Surely, it must've done what you wanted using $data as
    input, but your code just didn't assign the returned value to $data.


    Comment

    • Markku Uttula

      #3
      Re: str_replace

      InSeCo wrote:[color=blue]
      > str_replace($re plold, $repldata , $data);[/color]

      Perhaps it worked a bit better if you stored the result of str_replace()
      somewhere?

      Just wondering :)

      --
      Markku Uttula


      Comment

      • InSeCo

        #4
        Re: str_replace

        How do I store the result somewhere else??


        "Markku Uttula" <markku.uttula@ disconova.com> wrote in message
        news:Vsa7e.3803 $h_.1478@reader 1.news.jippii.n et...[color=blue]
        > InSeCo wrote:[color=green]
        >> str_replace($re plold, $repldata , $data);[/color]
        >
        > Perhaps it worked a bit better if you stored the result of str_replace()
        > somewhere?
        >
        > Just wondering :)
        >
        > --
        > Markku Uttula
        >
        >[/color]


        Comment

        • Markku Uttula

          #5
          Re: str_replace

          InSeCo wrote:[color=blue][color=green][color=darkred]
          >>> str_replace($re plold, $repldata , $data);[/color]
          >>
          >> Perhaps it worked a bit better if you stored the result of
          >> str_replace() somewhere?[/color]
          >
          > How do I store the result somewhere else??[/color]

          $data = str_replace($re plold, $repldata , $data);

          Please, read the manual. It has some great examples.


          --
          Markku Uttula


          Comment

          Working...