Matt Elhotiby
Matt Elhotiby

Reputation: 44086

php trim not trimming the spaces

I am trying to trim everything except the actual word so i have this wordpress function

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

which should return in this format

[email protected]

but its returning like this

                                                        [email protected]                  

with tons of spaces and i tried this

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

and

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

and both seem to still have the spaces in the html

here is my entire function

<?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 } ?>

Upvotes: 1

Views: 1280

Answers (2)

Heitor
Heitor

Reputation: 692

The explanation is that you are probably dealing with NON-BREAKING SPACES. Try this, it worked perfectly for me:

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

Upvotes: 0

FeRtoll
FeRtoll

Reputation: 1267

will this help?

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

or this one

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

Upvotes: 1

Related Questions