0

I have an app with fusion charts and I have to generate XML for him to render some graphs for users. But this XML string must be inline with no break lines and othes stuffs. But my query to retrieve graph data brings me an colunm with these break lines!

I tried this formatting on the string:

$txt = trim($txt);
$txt = str_replace("\r\n", " ", $txt);
$txt = preg_replace('~[\n|\r|\n\r|\r\n]{2,}~', " ", $txt);

This is an example of data with this problem:

- Eixo Inferior Entrada Com Camisa

- Montar As Calhas Aparafusadas Conforme Posição Anterior.
- Montar O Rodete Z15 - Ext. 1200.
- Manter A Identificação Na Peça.

Database: Oracle - Column Data Type: Varchar2

2 Answers2

2

Try:

$txt = preg_replace('~(*BSR_ANYCRLF)\R~', " ", $txt);
$txt = trim($txt);

Replaces all breaks with a space, trims the result.

If you want to support unicode, this is the utf-8 variant:

$txt = preg_replace('~\R~u', " ", $txt);
$txt = trim($txt);

See How to replace different newline styles in PHP the smartest way? with more detailed information.

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
0

If your graph data contains Linux-style line breaks ("\n"), the formatting you tried doesn't work because it only matches "\r\n".

This code should clear your data of both Windows- and Linux-style line breaks;

$txt = trim($txt)
$txt = str_replace("\r", " ", $txt);
$text = str_replace("\n", " ", $text);