Does single or double quote matter in str_ireplace in PHP ?

Posted by Richards on Stack Overflow See other posts from Stack Overflow or by Richards
Published on 2010-12-25T19:39:13Z Indexed on 2010/12/25 19:54 UTC
Read the original article Hit count: 232

Filed under:
|

Hi,

I've to replace newline (\n) with & in a string so that the received data could be parsed with parse_str() into array. The thing is that when I put \n in single quote it somehow turns out as to be replaced with a space:

str_ireplace(array('&', '+', '\n'), array('', '', '&'), $response)
"id=1 name=name gender=gender age=age friends=friends"

But when I put \n in double quotes then it works just fine:

str_ireplace(array('&', '+', "\n"), array('', '', '&'), $response)
"id=1&name=name&gender=gender&age=age&friends=friends"

Why is that so?

© Stack Overflow or respective owner

Related posts about php52

Related posts about string-replacement