...

View Full Version : preg_match for   in POST



petteyg359
12-14-2008, 06:28 PM
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.

hinch
12-14-2008, 11:28 PM
just use str_replace() since your storing all your html in a variable

petteyg359
12-15-2008, 02:48 AM
$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?

Leeoniya
12-15-2008, 08:02 AM
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

Fou-Lu
12-15-2008, 08:14 AM
$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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum