Search code examples
phptrim

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

Solution

  • will this help?

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

    or this one

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