Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    preg_match for   in POST

    I am attempting to remove   from a HTML source passed to PHP from a Greasemonkey script with xmlhttprequest. $data = preg_replace('/ /','',$data) where $data is the HTML source ($data=$_POST['html']) doesn't replace any of the  . preg_match() matches them fine, but the replace doesn't replace them.
    Last edited by petteyg359; 12-15-2008 at 01:48 AM.

  • #2
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    just use str_replace() since your storing all your html in a variable
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #3
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    $data = str_replace(' ','',$data) does the same thing $data = preg_replace('/ /','',$data) does... which is, sadly, nothing.

    EDIT: Found my error. htmlspecialchars() was passed the input data, rather than the output data. Can someone enlighten me as to why htmlspecialchars() would prevent matches being found?
    Last edited by petteyg359; 12-15-2008 at 02:00 AM.

  • #4
    Regular Coder
    Join Date
    Apr 2006
    Location
    Northbrook, IL
    Posts
    394
    Thanks
    8
    Thanked 6 Times in 6 Posts
    i had a not-so-fun time trying to figure out a similar problem : why regex whitespace character class (\s) wasnt replaing  .

    When i got really pissed off, i took out the big guns - Winhex. which shed some light on the issue. CR LF are 0D and 0A respectively. a space is hex 20 (i have known this for a long time). What i didnt know is that an   is A0.

    even though it shows up as a blank space, it may not qualify as regex whitespace or any whitespace you can type with your keyboard (easily), including ' '.

    ..that could be it. it's late, too lazy to actually read into problem.
    Leon

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by petteyg359 View Post
    $data = str_replace(' ','',$data) does the same thing $data = preg_replace('/ /','',$data) does... which is, sadly, nothing.

    EDIT: Found my error. htmlspecialchars() was passed the input data, rather than the output data. Can someone enlighten me as to why htmlspecialchars() would prevent matches being found?
    htmlspecialchars(' '); converts ' ' into its entity representation: ' '. I'm guessing thats why it won't match, & != &.
    nbsp; is not considered a whitespace char. Whitespace is: space, tab, line feed, form feed, and one other one (can't remember what its called). I believe 5.3 has also started matching on vertical spacing as well.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •