jcadima
8/27/2016 - 3:09 PM

Remove new lines, tabs, spaces, dots in PHP STDIN input

Remove new lines, tabs, spaces, dots in PHP STDIN input

http://stackoverflow.com/questions/3059091/how-to-remove-carriage-returns-from-output-of-string

<?php

$snip = str_replace('.', '', $snip); // remove dots
$snip = str_replace(' ', '', $snip); // remove spaces
$snip = str_replace("\t", '', $snip); // remove tabs
$snip = str_replace("\n", '', $snip); // remove new lines
$snip = str_replace("\r", '', $snip); // remove carriage returns

// OR ALL IN ONE LINE:
$snip = str_replace(array('.', ' ', "\n", "\t", "\r"), '', $snip);

// OR REGULAR EXPRESSIONS:
$snip = preg_replace('~[[:cntrl:]]~', '', $snip); // remove all control chars
$snip = preg_replace('~[.[:cntrl:]]~', '', $snip); // above + dots
$snip = preg_replace('~[.[:cntrl:][:space:]]~', '', $snip); // above + spaces