在文本区域中的数据之后删除空格[复制]

This question already has an answer here:

I input string to textarea such as below:

         email1@gmail.com   
   email@gmail.com
 email3@gmail.com
      email4@gmail.com

How to format they to:

email1@gmail.com
email@gmail.com
email3@gmail.com
email4@gmail.com

One email in one line in textarea. I want use PHP to make it. Please help me about solution, thanks you.

</div>

this should work in php str_replace(' ','',$yourText)

If you want to remove all whitespace:

$str = preg_replace('/\s+/', '', $yourstring);

Use the trim function to do this.

return(trim($str));