How to remove &nbsp/space from the front of data

Discussion in 'PHP' started by aniksaha, Dec 28, 2011.

  1. #1
    I have a space in front of data in mysql database.I can't remove the space when I fetching it from data base.Please suggest me how to overcome it.str_replace,html_entity_decode is not working.Please suggest.when the output is coming we can see there is   before data through page source.
     
    aniksaha, Dec 28, 2011 IP
  2. aniksaha

    aniksaha Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $data = htmlentities($Events[0]->Time, ENT_QUOTES | ENT_IGNORE, "UTF-8");
    echo str_replace(' ','',$data);

    using this I am able to remove extra character.
     
    aniksaha, Dec 28, 2011 IP
  3. pipsoup

    pipsoup Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you can try $str=trim($str);
     
    pipsoup, Dec 30, 2011 IP
  4. Jaxo

    Jaxo Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Or rtrim() if you really want to go crazy.
     
    Jaxo, Dec 31, 2011 IP
  5. Kenneth_Da

    Kenneth_Da Active Member

    Messages:
    91
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #5
    Use str_replace(' ','',$data); to resolve your problem.
    trim() function is cut space character at left and right of string.
    rtrim() function is only cut space character at right of string.
     
    Kenneth_Da, Jan 1, 2012 IP
  6. oliviergwada

    oliviergwada Greenhorn

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #6
    im facing the same problem.This post finally solve it..
    ive been googling for hours..
    good job man
     
    oliviergwada, Jul 23, 2012 IP
  7. marinseo

    marinseo Greenhorn

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    I am using ASP to read code from a text file that I am displaying on mypage. Because I do not want the code from the text file to be executed, Iused the Server.HTMLEncode() method to display it as it is in the file.However, the spaces used to indent lines is still removed by the browser.
     
    marinseo, Jul 23, 2012 IP