0

The main array is:

array (size=2)
  0 => 
    array (size=2)
      'message' => string 'Dear subscriber, 
We are working to resolve your link down issue. 
It will take approximately 2-4 hours to fix the issue.We appreciate your cordial support and patience during this time.

Thanks for being with us.
Techno' (length=231)
      'created_at' => string '01:04 pm 11/01/2022' (length=19)
  1 => 
    array (size=2)
      'message' => string 'Dear subscriber, 
We are working to resolve your link down issue. 
It will take approximately 2-4 hours to fix the issue.We appreciate your cordial support and patience during this time.

Thanks for being with us.
Techno' (length=231)
      'created_at' => string '01:04 pm 11/01/2022' (length=19)

After json_encode, collection becomes like this (Where extra \n, \r are included which we do not want:

'[{"message":"Dear subscriber, \nWe are working to resolve your link down issue. \nIt will take approximately 2-4 hours to fix the issue.We appreciate your cordial support and patience during this time.\n\nThanks for being with us.\nTechno","created_at":"01:04 pm 11\/01\/2022"},{"message":"Dear subscriber, \nWe are working to resolve your link down issue. \nIt will take approximately 2-4 hours to fix the issue.We appreciate your cordial support and patience during this time.\n\nThanks for'... (length=1173) 
Mishu Das
  • 19
  • 3
  • 1
    write your messages on one line. \n are just json transcription of new lines. – TomVerdier Jan 12 '22 at 10:05
  • Then what does \r mean? – Mishu Das Jan 12 '22 at 10:11
  • Can we get rid of these special characters? – Mishu Das Jan 12 '22 at 10:11
  • yes by removing new lines. New lines are characters, but you don't see them, they modify layout. But if there are new lines, you'll get \n in json – TomVerdier Jan 12 '22 at 10:17
  • In curl response, we get data like this including n. This does not make sense to us. – Mishu Das Jan 12 '22 at 10:19
  • {"result":[{"message":"Dear subscriber, nWe are working to resolve your link down issue. nIt will take approximately 2-4 hours to fix the issue. – Mishu Das Jan 12 '22 at 10:19
  • nWe, nIt How can we detect new lines from here? – Mishu Das Jan 12 '22 at 10:20
  • Why does it "not make sense" to you, that after a greeting formula like "Dear subscriber", there is a newline first ...? Or that multiple sentences are separated from each other with a line break in between them? That seems like a pretty normal thing to do. Reads & looks better, than if everything was just written in one long line. But if you insist on not wanting them, then loop over your data, and remove them via search&replace ...? – CBroe Jan 12 '22 at 10:38

1 Answers1

0

If all what you need is to remove those two characters you mentioned (new lines basically) you can try something like this on json_encode $result:

$result = str_replace("\\n", '', $result);

$result = str_replace("\\r", '', $result);

More options you can find here for example.

Tomasz Wu
  • 29
  • 3