Explode php string

Asked

Viewed 80 times

0

I have a strange problem at least for me.

I have a string in php:

$str='10,20,30,40';
explode(',',$str);

When I do the string explode and pass the result to a view via $ajax I get the following result:

"\n n10203040"

Can someone explain to me why "\n n"?

  • Have you tried to put the result of the explosion inside the json_encode before sending?

  • 1

    It’s line breaking, use a trim() in string.

  • @rray missed the answer :)

  • I’ve tried it doesn’t work.

1 answer

0

Or you can do the following:

<?php
 $json = str_replace('\n', '', $json);
?>

is an option when you have n between text

  • I’ve tried and it doesn’t work.

  • Explain your mistake and I’ll try to help

  • Thank you all, and I’m sorry I’m only responding now. I already solved the problem, deleted the code and rewritten it and it worked fine. Why? I have no idea...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.