how to write variables value with file_put_contents()?

前端 未结 5 931
北海茫月
北海茫月 2021-01-21 10:28

Have been trying to figure this out all day assuming its just a small error.....

I\'m trying to use the file_put_content to put a variables value into anoth

5条回答
  •  悲&欢浪女
    2021-01-21 11:24

    You're using ' to define the string, this means that the value will be left unparsed. The trick here, though, is that you want $UNQ_ID parsed, but you want $affiliate_reference left as is. This means you have to escape or manually concatenate

    I would use this instead:

    ''
    

    Notice, I am using the single quote for the majority of the string. This is purposeful, you don't want the $affiliate_reference to be output. You only want $UNQ_ID turned into its string equivalent. Your other option is to use " and escape the $:

    ""
    

    Note the \ to escape $ in front of $affiliate_reference.

    I generally prefer the first way, color syntax highlighters will make that very obvious (even notice how SO handles it), while the second example causes highlighters to glaze over the whole thing. It is a preference, but it is an important one.

    Of course, there is always the silly:

    $a = '$';
    

    followed by

    ""
    

    Use that only with people you don't like.

提交回复
热议问题