Jump to content

Archived

This topic is now archived and is closed to further replies.

jimbudd

write file

Recommended Posts

hi i CAN get my php write file script to dynamically insert a name,
but CANT get the name in the result file, to be inside inverted commas as the script and wont parse.
eg.

my create file script:

[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]$content3 = '<?php $thisbio = '. $username .'";?>
';
write_file("$webpath/$username/ID.php","$content3\n");[!--colorc--][/span][!--/colorc--]


dynamically loads the user and writes the result ID.php file:

[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]<?php

$thisbio = blackbetty;

?>[!--colorc--][/span][!--/colorc--]


but here's my problem, the result needs to look like this:

[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]<?php

$thisbio = 'blackbetty';

?>[!--colorc--][/span][!--/colorc--]


so my newbie attempt was this, but of course wont parse:


[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]$content3 = '<?php $thisbio = ''. $username .''";?>
';
write_file("$webpath/$username/ID.php","$content3\n");[!--colorc--][/span][!--/colorc--]



so can someone please help me to write this correctly??
many thanks,
jimbudd


Share this post


Link to post
Share on other sites
if you ever want to insert a character that you're using as a string delimiter (that is, double or single quotes), you can escape it to have its delimitation meaning nulled. in lighter terms, escaping a character makes it mean nothing:

[code]$content3 = '<?php $thisbio = \''. $username .'\';?>';[/code]

notice that i escape (add a backslash) before the two single quotes that i want to appear in the string itself. an alternative would be to use double quotes, like so:

[code]$content3 = "<?php \$thisbio = '$username';?>";[/code]

here we have to escape the first $ since otherwise PHP will try to insert the actual value of $thisbio, not simply insert a literal $thisbio.

Share this post


Link to post
Share on other sites
THANKS!!!!!

[!--quoteo(post=357207:date=Mar 22 2006, 01:13 AM:name=akitchin)--][div class=\'quotetop\']QUOTE(akitchin @ Mar 22 2006, 01:13 AM) [snapback]357207[/snapback][/div][div class=\'quotemain\'][!--quotec--]
if you ever want to insert a character that you're using as a string delimiter (that is, double or single quotes), you can escape it to have its delimitation meaning nulled. in lighter terms, escaping a character makes it mean nothing:

[code]$content3 = '<?php $thisbio = \''. $username .'\';?>';[/code]

notice that i escape (add a backslash) before the two single quotes that i want to appear in the string itself. an alternative would be to use double quotes, like so:

[code]$content3 = "<?php \$thisbio = '$username';?>";[/code]

here we have to escape the first $ since otherwise PHP will try to insert the actual value of $thisbio, not simply insert a literal $thisbio.
[/quote]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.