Well... this is annoying. I can't get this simple str_replace to remove a '&'.

I have extracted this link:

$sprint_user_photo_link = 'http://pictures.sprintpcs.com//mmps/RECIPIENT/001_xxxxb848d2ff0ca3_1/2.2?inviteToken=NEqrxxJ5m8awcUcLo7qL&limitsize= ';

and in my happy world the code below should work

$image_url = str_replace('&limitsize=', '', $sprint_user_photo_link);

I've tried different ways and most times it does nothing and if is use str_replace just only '&' it does replace it with '&'

confused in kansas

Just need to clip those last characters &limitsize=

    Try ereg_replace():

    $image_url = ereg_replace('&limitsize=', '', $sprint_user_photo_link);
    

    Or '&' might be a special character so it might need to be escaped like so:

    $image_url = str_replace('\&limitsize=', '', $sprint_user_photo_link);
    

    Neither tested, just guessing.

      I copied and pasted your code, and it worked fine. Perhaps you are outputting the $sprint_user_photo_link variable instead of the $image_url that you save the replaced text in?

        Thanks for the suggestions. I know we are in the neighborhood with the 'special character' issues.

        but neither of those worked. I was also looking for some clipper commands. Like go to the end of this string and chop off 1 character.

        lot of remove carriage control code. (trim) But nothing yet that just says .... kill the last character.

        Anyway the '&' is very special. grrrrrrr

        kc

          You could extract just that section of the sting (the bit without '&limitsize=' in).
          Like so:

          $var = substr($var, 0, strlen($var) - strlen("&limitsize="));
          

          Try that, I haven't, lol.

            NogDog wrote:

            I copied and pasted your code, and it worked fine. Perhaps you are outputting the $sprint_user_photo_link variable instead of the $image_url that you save the replaced text in?

            Maybe it's different php code level. I think I have the displays right because I did everything but the '&' and get this output:

            Sprint user photo link after cleanup: http://pictures.sprintpcs.com//mmps/RECIPIENT/001_26xxx848d2ff0ca3_1/2.2?inviteToken=NEqrxxx5m8awcUcLo7qL& .

            I'll keep trying.

              What's happens if you only replace the "&" character ?

                If you are bothered, my code worked perfectly.

                $sprint_user_photo_link = 'http://pictures.sprintpcs.com//mmps/RECIPIENT/001_xxxxb848d2ff0ca3_1/2.2?inviteToken=NEqrxxJ5m8awcUcLo7qL&limitsize= ';
                $image_url = $var = substr(trim($sprint_user_photo_link), 0, strlen($sprint_user_photo_link) - strlen("&limitsize="));
                
                echo $image_url;
                // http://pictures.sprintpcs.com//mmps/RECIPIENT/001_xxxxb848d2ff0ca3_1/2.2?inviteToken=NEqrxxJ5m8awcUcLo7qL
                
                  suntra wrote:

                  What's happens if you only replace the "&" character ?

                  code here:

                  $image_url = str_replace('limitsize=', '', $sprint_user_photo_link);
                  
                  
                  
                  echo nl2br(".  \n Sprint user photo link after cleanup:  $image_url   ");
                  
                  
                  
                  
                  
                  
                  $image_url = str_replace('&', '', $image_url);
                  
                  //   put in here <---           replace this, with this, in here
                  
                  echo nl2br(".  \n Sprint user photo link after cleanup #2 for '&':  $image_url   .");
                  
                  
                  
                  
                  
                  

                  Output below: --------------------------------------------------------------------

                  this is snatch Sprint photo link . Sprint photo link is (before clean) http://pictures.sprintpcs.com//mmps/RECIPIENT/001_266db848d2ff0ca3_1/2.2?inviteToken=NEqrJUJ5m8awcUcLo7qL&limitsize= .

                  ..

                  Sprint user photo link after cleanup: http://pictures.sprintpcs.com//mmps/RECIPIENT/001_266db848d2ff0ca3_1/2.2?inviteToken=NEqrJUJ5m8awcUcLo7qL& .

                  Sprint user photo link after cleanup #2 for '&': http://pictures.sprintpcs.com//mmps/RECIPIENT/001_266db848d2ff0ca3_1/2.2?inviteToken=NEqrJUJ5m8awcUcLo7qLamp; .

                    Like i said, mine works fine.

                    Why mess around when you have something that works?

                      rowanparker wrote:

                      Like i said, mine works fine.

                      Why mess around when you have something that works?

                      Rowan, Thanks but
                      It didn't work for me. Unless there's some other mistake I'm missing.

                      $image_url = $var = substr(trim($sprint_user_photo_link), 0, strlen($sprint_user_photo_link) - strlen("&limitsize=")); 
                      
                      echo nl2br(".  \n Sprint user photo link after cleanup:  $image_url   ");

                      output:

                      Sprint user photo link after cleanup: http://pictures.sprintpcs.com//mmps/RECIPIENT/001_266db848d2ff0ca3_1/2.2?inviteToken=NEqrJUJ5m8awcUcLo7qL&

                      This is approaching 'bug' territory. It found it and replaced it but ignored the '&'.

                      In some doc I'm seeing (and it also show in my reply before this one) that '&' is sometimes represented by '&amp;'.

                      Still researching.

                        Try:

                        $image_url = $var = substr(trim($sprint_user_photo_link), 0, strlen($sprint_user_photo_link) - strlen("&limitsize=") + 1);
                        
                        echo nl2br(".  \n Sprint user photo link after cleanup:  $image_url   ");[
                        

                        Should work, unless it just does not like your, lol.

                          kansaschuck wrote:

                          ...
                          In some doc I'm seeing (and it also show in my reply before this one) that '&' is sometimes represented by '&amp;'.

                          Still researching.

                          Are you doing a "view source" in your browser to see what is really there, as opposed to just what the browser itself is showing?

                          If it might be "&amp;", you could handle either/or with either of these:

                          $image_url = str_replace(array('&limitsize=', '&amp;limitsize=', '', $sprint_user_photo_link);
                          // ...or...
                          $image_url = preg_replace('/&(amp;)?limitsize=/', '', $sprint_user_photo_link);
                          
                            rowanparker wrote:

                            Like i said, mine works fine.

                            Why mess around when you have something that works?

                            this worked for me.

                            $image_url = str_replace('&amp;limitsize=', '', $sprint_user_photo_link);

                            whacha think?

                              Write a Reply...