title: Wordpress remove white spaces
body: <p>I've this code which runs the excerpt outside the loop in wordpress.</p>
  
  <pre><code>&lt;?php
  function get_excerpt_by_id($post_id){
  $the_post = get_post($post_id); //Gets post ID
  $the_excerpt = $the_post-&gt;post_content; //Gets post_content to be used as a basis for the excerpt
  $excerpt_length = 35; //Sets excerpt length by word count
  $the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
  $words = explode(' ', $the_excerpt, $excerpt_length + 1);
  if(count($words) &gt; $excerpt_length) :
  array_pop($words);
  array_push($words, '…');
  $the_excerpt = implode(' ', $words);
  endif;
  $the_excerpt = '&lt;p&gt;' . $the_excerpt . '&lt;/p&gt;';
  return $the_excerpt;
  }
  ?&gt;
  </code></pre>
  
  <p>As you can see it removes all the content like images and other stuff and leaves only the text, but when it does this it also outputs a lot of white spaces (returns). I've tried to remove them with \n, \t, \r but obviously I don't know where to put the code to make it work. Can you help me with this?</p>