[wp-trac] [WordPress Trac] #10376: White space should be collapsed after tags are stripped in wp_trim_excerpt

WordPress Trac wp-trac at lists.automattic.com
Sat Jul 11 13:35:20 UTC 2009


#10376: White space should be collapsed after tags are stripped in wp_trim_excerpt
-------------------------+--------------------------------------------------
 Reporter:  sojweb       |       Owner:                                         
     Type:  enhancement  |      Status:  new                                    
 Priority:  normal       |   Milestone:  2.8.2                                  
Component:  Formatting   |     Version:  2.8.1                                  
 Severity:  normal       |    Keywords:  has-patch, the_excerpt, wp_trim_excerpt
-------------------------+--------------------------------------------------

Comment(by dd32):

 No. a trim would not work.

 the issue here, is that
 {{{
 $in = "A<test> <test> <test> B";
 $in = strip_tags($in);
 echo $in; //is now 3 spaces between a and b
 }}}

 when you explode by spaced, you end up with spaces being words, ie.
 {{{
 $in = "   ";
 $in = explode(' ', $in);
 var_dump($in);
 ---
 array
   0 => string '' (length=0)
   1 => string '' (length=0)
   2 => string '' (length=0)
   3 => string '' (length=0)
 }}}


 This is what i'd use myself to get the words:
 {{{
 $a = "          This is a test";
 preg_match_all('|\b([^\W]+?)\b|', $a, $words);
 $words = $words[1];

 result:

 array
   0 => string 'This' (length=4)
   1 => string 'is' (length=2)
   2 => string 'a' (length=1)
   3 => string 'test' (length=4)
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/10376#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list