Jump to content


Photo

write file


  • Please log in to reply
2 replies to this topic

#1 jimbudd

jimbudd
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 March 2006 - 05:40 AM

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




#2 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 22 March 2006 - 06:13 AM

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:

$content3 = '<?php $thisbio = \''. $username .'\';?>';

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:

$content3 = "<?php \$thisbio = '$username';?>";

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.

#3 jimbudd

jimbudd
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 March 2006 - 06:57 AM

THANKS!!!!!

[!--quoteo(post=357207:date=Mar 22 2006, 01:13 AM:name=akitchin)--][div class=\'quotetop\']QUOTE(akitchin @ Mar 22 2006, 01:13 AM) View Post[/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:

$content3 = '<?php $thisbio = \''. $username .'\';?>';

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:

$content3 = "<?php \$thisbio = '$username';?>";

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]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users