kts Posted February 6, 2009 Share Posted February 6, 2009 In the description field, I have bullets and such. I have used strip_tags and other methods of replace to remove this, but it continues happening. Has anyone had any similar problems that they have solved? Shows up like O Blah blah blah O Blah blah blah Thanks! Link to comment https://forums.phpfreaks.com/topic/144082-having-trouble-making-data-csv-safe/ Share on other sites More sharing options...
gevans Posted February 6, 2009 Share Posted February 6, 2009 Can you give us some code and explain a bit better, I'm not totally sure what you get and what you expect to get Link to comment https://forums.phpfreaks.com/topic/144082-having-trouble-making-data-csv-safe/#findComment-755984 Share on other sites More sharing options...
omfgthezerg Posted February 6, 2009 Share Posted February 6, 2009 Try preg_replace? $string = preg_replace('/[^\w\d]/', '', $string); Note: This is a very aggressive replace and will replace anything that is not a word and not a number. Link to comment https://forums.phpfreaks.com/topic/144082-having-trouble-making-data-csv-safe/#findComment-755986 Share on other sites More sharing options...
gevans Posted February 6, 2009 Share Posted February 6, 2009 Try preg_replace? $string = preg_replace('/[^\w\d]/', '', $string); Note: This is a very aggressive replace and will replace anything that is not a word and not a number. It also takes a lot longer than the standard string replace methods and is a last resort in standard cases (personally) Link to comment https://forums.phpfreaks.com/topic/144082-having-trouble-making-data-csv-safe/#findComment-755988 Share on other sites More sharing options...
kts Posted February 6, 2009 Author Share Posted February 6, 2009 it has gotten quite messy, been pulling out all stops haha function csvsafe($str=''){ return '"'.trim(str_replace('"','\'',$str)).'"'; } $description = ''.strip_tags(csvsafe(strip_tags(str_replace(chr(13)," ",str_replace(chr(10)," ",($desc['value'])))))); $data .= str_replace($search, $replace, $description).','; Link to comment https://forums.phpfreaks.com/topic/144082-having-trouble-making-data-csv-safe/#findComment-755990 Share on other sites More sharing options...
gevans Posted February 6, 2009 Share Posted February 6, 2009 Can you give me an example of input text and the expected output text? Link to comment https://forums.phpfreaks.com/topic/144082-having-trouble-making-data-csv-safe/#findComment-755996 Share on other sites More sharing options...
kts Posted February 6, 2009 Author Share Posted February 6, 2009 Sorry for the delay found out more the actual text is this Product Features: O Piston-driven Microprocessor O Adjustable Speed Settings O Adjustable Suction Knobs From 0 - 250 MmHg. O Built-in Bottle Holders O Breast Pump O Includes 12 V Car Adapter, Hospital Grade Cord O Designed For Medical Facilities Or Moms Of Twins and that is how it is coming out, im trying to remove the O etc etc etc and just make it plain text friendly Link to comment https://forums.phpfreaks.com/topic/144082-having-trouble-making-data-csv-safe/#findComment-756117 Share on other sites More sharing options...
gevans Posted February 6, 2009 Share Posted February 6, 2009 And do you have an example of your CSV file? Link to comment https://forums.phpfreaks.com/topic/144082-having-trouble-making-data-csv-safe/#findComment-756119 Share on other sites More sharing options...
kts Posted February 6, 2009 Author Share Posted February 6, 2009 its a rather large file, but that is literally the pasted out.. the situation is i need this to be able to be just flat text for an import Link to comment https://forums.phpfreaks.com/topic/144082-having-trouble-making-data-csv-safe/#findComment-756129 Share on other sites More sharing options...
gevans Posted February 6, 2009 Share Posted February 6, 2009 oh sorry, that's how it looks in the file, if it's standard like that why not just not print the first 4 characters echo substr($your-line, 4); Link to comment https://forums.phpfreaks.com/topic/144082-having-trouble-making-data-csv-safe/#findComment-756137 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.