Jump to content

write file


jimbudd

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


Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.