Link to home
Start Free TrialLog in
Avatar of ray-solomon
ray-solomonFlag for United States of America

asked on

Cleaning textarea contents

I created this to remove duplicates and trim each line of a textarea box. And it works.

I am wondering if there is a more efficient way to write this and possibley make it into a function.

// TRIM, CREATE ARRAY, REMOVE DUPLICATES, MAKE STRING, TRIM AGAIN
$array = array_unique(explode("\r\n", trim($field1)));
$cleaned = implode("\r\n", $array);
$trimmed = preg_replace ( "/\s\s+/" , "\r\n" , $cleaned );
echo $trimmed;
ASKER CERTIFIED SOLUTION
Avatar of RWJDCom
RWJDCom
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ray-solomon

ASKER

Thanks for confirming this, I implemented this as a function and it helped reduce my 27 lines of code down to 9 lines.