Removing Whitespace?

Discussion in 'PHP' started by Borghunter, Oct 22, 2006.

  1. #1
    I am trying to remove whitespace with PHP from something like this:
    <body>
                                                               Hi
            </body>
    Code (markup):
    Which outputs simply "Hi" in HTML. But I don't want my PHP script running the whitespace. How would I get rid of the whitespace, i've tried the following:

    str_replace(" ", "", $something);
    trim($something);


    Anyone have any ideas?
     
    Borghunter, Oct 22, 2006 IP
  2. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could try a regular expression. Something like

    /<body>\s*([\s\S]+?)\s*<\/body>/s
    Code (markup):
    coupled with the preg_match function might do the trick.

    You'll need to check that regular expression though, I haven't tested it and I'm not confident enough in my regex knowledge to say it will definitely work.
     
    streety, Oct 22, 2006 IP
  3. Borghunter

    Borghunter Well-Known Member

    Messages:
    212
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Well, I'm not worried about the <body> tags, i was just using those as an example. But lets see...
    Nope didn't work :(
     
    Borghunter, Oct 22, 2006 IP
  4. Borghunter

    Borghunter Well-Known Member

    Messages:
    212
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #4
    I think I'm fine now, Since it's in a MySQL database I used Like %whatever% . Works like a charm, I can't believe I didn't think of that in the first place :p
     
    Borghunter, Oct 22, 2006 IP