jimbudd Posted March 22, 2006 Share Posted March 22, 2006 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 https://forums.phpfreaks.com/topic/5473-write-file/ Share on other sites More sharing options...
akitchin Posted March 22, 2006 Share Posted March 22, 2006 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 https://forums.phpfreaks.com/topic/5473-write-file/#findComment-19571 Share on other sites More sharing options...
jimbudd Posted March 22, 2006 Author Share Posted March 22, 2006 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 https://forums.phpfreaks.com/topic/5473-write-file/#findComment-19576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.