[Easy] Please help what is the right replacement code

Discussion in 'PHP' started by basketmen, Aug 23, 2012.

  1. #1
    I have a variable, lets say $peoplename, that have dynamic output

    for example

    or



    like you see, sometime there is   characther in the output, i want to replace that character in the output, please help what is looks like the right replacement code, this should be easy enough, already tried this but its looks like still not right


     
    basketmen, Aug 23, 2012 IP
  2. shubhamm

    shubhamm Member

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    shubhamm, Aug 23, 2012 IP
  3. Ratty

    Ratty Active Member

    Messages:
    565
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    95
    Digital Goods:
    1
    #3
    Your problem is in the usage of str_replace. Here is how the php manual says to use it (http://php.net/manual/en/function.str-replace.php)

    mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
    PHP:
    Your code should look like this.

    $peoplename = 'michael ';
    $nbsp = ' ';
    $peoplenamereplaced = str_replace($nbsp, '', $peoplename);
    echo $peoplenamereplaced;
    PHP:
     
    Ratty, Aug 24, 2012 IP