367 views
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
Loading ... Loading ...

12.05.08

A Big Space in between Firefox and Internet Explorer

Posted in Blogroll, News, Tech at 4:08 pm by liviu.tudor View Liviu Tudor's profile on LinkedIn

For those of you who tried to put together a “flatten” function cross browser to eliminate consecutive spaces and/or trim some text that is retrieved from the HTML page itself, you might have noticed that a simple regex of the kind

/\s+/gm

is simply not enough and occasionally Internet Explorer would still return a string with multiple consecutive space characters! The reason for that is that Internet Explorer does NOT treat
(non-breaking spaces) as a space — and therefore the \s won’t match it! In order to include this in your match, look at W3C list of HTML entities, and it transpires that is the same as — in other words 160 is the decimal code for this character (which is A0 in hex by the way). So to include this when searching for spaces, your regex now becomes:

/(\s|\xA0)+/gm

and you’ll notice that now you “catch” the non-breaking spaces in IE as well as Firefox (which does the right thing and treats the non-breaking spaces as proper spaces) — yahoo!

See Also

2 Comments »

  1. Explorer » A Big Space in between Firefox and Internet Explorer said,

    May 12, 2008 at 6:15 pm

    [...] liviu.tudor wrote an interesting post today on A Big Space in between Firefox and Internet ExplorerHere’s a quick excerpt… and/or trim some text that is retrieved from the HTML page itself, you might have noticed that a simple regex of the kind /s+/gm is simply not enough and occasionally Internet Explorer would still return a string with multiple [. … [...]

  2. Amit said,

    September 8, 2008 at 5:26 pm

    Yet another IE drawback.Thanks for the post..was going nuts,wondering y IE doesnt remove  

Leave a Comment

Interesting site about getting Londoners chatting during their daily commute I Can Talk, Me!

( ! ) Warning: fsockopen() [function.fsockopen]: unable to connect to twitter.com:80 (Network is unreachable) in /usr/share/php/libphp-snoopy/Snoopy.class.php on line 1142
Call Stack
#TimeMemoryFunctionLocation
11.149720429240shutdown_action_hook( )../wp-settings.php:0
21.149720429240do_action( )../wp-settings.php:729
31.149920429240call_user_func_array ( )../plugin.php:339
41.149920429240aktt_update_tweets( )../plugin.php:0
51.161720674748Snoopy->fetch( )../twitter-tools.php:702
61.161820674924Snoopy->_connect( )../Snoopy.class.php:143
71.161820674924fsockopen ( )../Snoopy.class.php:1142