-1

Let us say I have string like below $comments = Windows Embedded Compact (Windows CE) or Windows Server. Defunct Windows families include Windows 9x and Windows Mobile. [CR][LF] [CR][LF] Microsoft introduced an operating environment named Windows on November 20, 1985, as a graphical operating system shell for MS-DOS in response to the growing interest in graphical user interfaces (GUIs).

Note: [CR][LF] are manually added for the question. I found this issue when any user copy and paste any html content in the comments rich text area box we are observing these elements.

Is there way where we can replace these with \n\r in PHP.

I tried something like this

$comments = preg_replace("/\r\n\r\n|\r\r|\n\n/", "<br />", $comments);

it didn't give me any proper result.

Ali Zia
  • 3,825
  • 5
  • 29
  • 77
Krishna
  • 39
  • 9

1 Answers1

0

Assuming you want to replace any combinations of [CR] and [LF] by [CR][LF] (i.e. \r\n, not \n\r), try this:

$string = ".....[CR].....[LF]...[CR][LF].....[CR][CR].......[LF][LF].......";
$result = preg_replace('/\r\n|\n\r|\r|\n/', '\r\n', $string);
hherger
  • 1,660
  • 1
  • 10
  • 13
  • @Wiktor: Thanks - you are right. I'll update the example. – hherger Jan 20 '16 at 12:26
  • Still, it is not clear if your answer is correct or not, since the question is unclear. – Wiktor Stribiżew Jan 20 '16 at 12:29
  • @WiktorStribiżew: If my string is having such kind of characters i want to escape them before sending the request to the API.Please let me know if my question is still unclear. I will improve myself in providing the right question – Krishna Jan 20 '16 at 13:04