Hey DaniWeb! You've proved to be a reliable resource before so let's see if you can come through again.

I have a script which creates a dynamic image and posts values to the image that are pulled from an SQL database. For various reasons, I have to create a folder called "<username>.png" (using mkdir()) for each user that requests a signature. I then create an index.php file within this folder that tells the dynamic image what to do. I'd like to be able to create this file while keeping some variables in plain text and others translated into their correct values. I thought maybe this would work:

$string = "$blahblah " . $blah . " $foo";

... where $string would be the content of the new file. However, the variables in quotes are translated by the server and I am unable to keep their original formatting. How would you guys go about this?

You can use single quotes to do this. Take a look at the difference between these lines of code and you will see:

$foo = "Something witty...";
$blah = "Something strange...";
$string = "$blah"; // $string now equals the string {Something strange...}
$string = '$foo'; // $string now equals the string {$foo}
$string = "1 2 3 '$blah' 4 5 6"; // $string now equals the string {1 2 3 'Something strange...' 4 5 6}
$string = '1 2 3 "$foo" 4 5 6'; // $string now equals the string {1 2 3 "$foo" 4 5 6}

You can also use the backslash character ( \ ) to escape certain characters in a string, like so:

$string = "I am escaping \$the dollar sign..."; // $string now equals the string {I am escaping $the dollar sign...}

Hope this helps...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.