简体   繁体   中英

PHP: remove MySQL formatting such as line break and commas

I'm making a CSV file, one of the database filed has stored a section called comments/note which obviously have some commas and line breaks in it too. Looked around the web found usage of preg_replace(), not much familiar with regular expressions there fore combined two different ones and not getting anything in result its totally blank and i know all records have some sort of comments in it

this i used

preg_replace( "/\r|\n/|/[,]/", "", $string )

Please what do I need to do here get one text back without line breaks and commas

Regards

You can do it using strip_tags() and preg_replace() ;

$clean_str = trim(preg_replace('/\s\s+/', '', strip_tags($string)));

or try this

$clean_str = str_replace(array("\r\n","\r","\n", ","), '', strip_tags($string));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM