Remove enter char from string and CSV files issues.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
raulbolanos
Forum Newbie
Posts: 14
Joined: Fri May 07, 2010 3:14 pm

Remove enter char from string and CSV files issues.

Post by raulbolanos »

Hi guys,

I got above the following string:

"EN ABRIL SE INCREMENTAN LOS PRECIOS DE VENTA POR EL AUMENTO EN LOS INSUMOS DE IMORTACION.

SE ESPERA QUE DISMINUYAN PARA INCREMENTAR LA DEMANDA."

this String it's going to be saved into a CSV file and every enter chars inserts the next sentence line in other line... I would like to have all together.

I have already replace the strings the \r ,\t and \n characters and it's still doesn't work. Is there any other speacial character for enter? As far as I know it was \r\n.

Code: Select all

$observacion = str_replace('\n', '', mysql_result($result, 0));
	  $observacion = str_replace('\r', '', $observacion);
	  $observacion = str_replace('\t', '', $observacion);
	  $observacion = str_replace(',', ';', $observacion);
	  $observacion = str_replace('\r\n', '', $observacion); 
I also had troubles with the comas ',' because the columns are separeted with ',' and the remarks contain comas as well. I have reaplace the comas with semicolon ';' in order to solve this problem but it looks odd. Do you know another solution for this?


Thank you in advance,

cheers.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: Remove enter char from string and CSV files issues.

Post by markusn00b »

Escape characters aren't parsed in single-quoted strings, so '\n' is literally interpreted as a backslash followed by an 'n'. Use double-quoted strings instead.
raulbolanos
Forum Newbie
Posts: 14
Joined: Fri May 07, 2010 3:14 pm

Re: Remove enter char from string and CSV files issues.

Post by raulbolanos »

markusn00b wrote:Escape characters aren't parsed in single-quoted strings, so '\n' is literally interpreted as a backslash followed by an 'n'. Use double-quoted strings instead.
Thank you man.

It works perfectly now.
Post Reply