title: Replace spaces and newlines with a comma in php
body: <p>I searched but couldn't find anything that helped</p>
  
  <p>So, I have a bunch of data I need to basically just put commas between, the data all comes from records so it comes in like:</p>
  
  <pre><code>13
  566
  888
  958
  898
  </code></pre>
  
  <p>and I need to output it like:</p>
  
  <pre><code>13,566,888,958,898
  </code></pre>
  
  <p>even better if I can move any 2 digits one over like:</p>
  
  <pre><code>566,13,888,958,989
  </code></pre>
  
  <p>I know it should be pretty simple, so basically I just made a form, pass it with GET and then read the variable from the url, then I'm trying to use str_replace(" ",",",$outtext) to get replace the spaces with commas so I can echo it out and just copypasta it in real quick, problem is, I think the data comes in with a new line and I don't know how to replace that, I've tried "\n" and "%0D%0A" but it doesn't replace it, it just gives it right back to me with the spaces.</p>
  
  <p>Anyway, here's the code I'm using, maybe someone can tell me the simple thing that I'm missing, </p>
  
  <pre><code>&lt;?php
  if (isset($_GET['intext'])) {
      $outtext=$_GET['intext'];
  
      $newout=str_replace(" ", ",", $outtext);
  
      echo $newout;
      //testing
      //echo(str_replace(" ",",","$outtext"));
  }
  ?&gt;
  </code></pre>
  
  <p>and the html</p>
  
  <pre><code>&lt;form name="indata" id="indata" method="get" action="index.php"&gt;
          &lt;textarea id="intext" name="intext"&gt;&lt;/textarea&gt;
          &lt;input type="submit" id="submit" name="submit"&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>I also thought about tossing it into an array and imploding it, but it's been a while and I forget how to do that.</p>