Tuesday 6 November 2018

php - how to not parse double quotes within double quotes

Answer


Answer




Hello there :) I have a script in PHP that creates a file (with the function "file_put_contents()") , and it will put the contents of a PHP file within the file it just created. Within the PHP file, there are double quotations, so as i try to implement the code that i want to put into this newly made PHP file, it has double quotations, and the way how file_put_contents works is the second part of it uses double quotations as well.



To put it into perspective, this is how it goes: file_put_contents('file.php',"code with "" in it")
so as you can see, the double quotations get in the way of the PHP files double quotes.




My question is, how do i get the text within the quotes to not parse?
Thanks


Answer



use \ more info



file_put_contents('file.php',"code with \"\" in it")


or use ' to quote second param




file_put_contents('file.php','code with "" in it')

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...