2011-01-27 168 views
1

我試圖削減除了實際字的一切,所以我有這個WordPress功能PHP修剪不修剪的空間

the_author_meta('author_image', $_GET['author']); 

應該返回該格式

[email protected] 

但其返回這樣

             [email protected]     

與噸的空間,我試過這個

<?php print trim($matching_image, "\n"); exit; ?> 

<?php print trim($matching_image); exit; ?> 

兩者似乎仍然有空間在html

這裏是我的全部功能

<?php $matching_image = the_author_meta('author_image', $_GET['author']); ?> 
<?php print trim($matching_image, "\n"); exit; ?> 
<div class="post" id="post-<?php the_ID(); ?>"> 
<?php if (is_numeric($matching_image)){ ?> 
<img src="/wp-content/authors/missing.jpg" alt="<?php the_author(); ?>" title="<?php the_author(); ?>" /> 
<?php }else{ ?> 
<img src="/wp-content/authors/<?php print $matching_image; ?>" alt="<?php the_author(); ?>" title="<?php the_author(); ?>" /> 
<?php } ?> 
+4

確定的空間從失敗`TRIM()`來了嗎?添加一些額外的字符,如`print「〜」。 trim($ matching_image,「\ n」)。 「〜」`以確保它不是來自其他地方。 – Maerlyn 2011-01-27 19:59:30

回答

1

這能否幫助?

$matching_image = preg_replace("/^(\\s)*|(\\s)*$/","$2",$matching_image); 

或這一個

$matching_image = preg_replace("/^(\\s)*\|(\\s)*$/","$2",$matching_image); 
0

的解釋是,你可能處理非中斷空格。試試這個,它的工作完美的我:

trim($matching_image, chr(160)); // 160 is ASCII code for non-breaking space