Reply
PHP Create File
Old 11-14-2007, 07:58 PM PHP Create File
Experienced Talker

Posts: 33
Name: matt
I have a php script that needs to write variables to another file, is currently use:
PHP Code:
$File "installconfig.php"
$Handle fopen($File'w');
$Data '$dbloc\n'
fwrite($Handle$Data); 
$Data '$dbname\n'
fwrite($Handle$Data);
$Data '$dbuser\n'
fwrite($Handle$Data); 
$Data '$dbpass\n'
fwrite($Handle$Data);
$Data '$dbprefix\n'
fwrite($Handle$Data);
print 
"Executed MySQL Commands<br />"
fclose($Handle); 
but all that comes out in the file is:
Code:
$dbloc\n$dbname\n$dbuser\n$dbpass\n$dbprefix\n
melefire is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 11-14-2007, 09:12 PM Re: PHP Create File
Extreme Talker

Posts: 235
Location: United States
Variable names and special characters (e.g., \n, \r, \t, etc.) are not parsed when they are inside of single quotes.

If you change them to double quotes, it should work properly.
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.
frost is offline
Reply With Quote
View Public Profile
 
Old 11-15-2007, 04:25 PM Re: PHP Create File
Experienced Talker

Posts: 33
Name: matt
ok thanks, now how would i do something like writing this into the file:

$dbloc=[$dbloc from file writing the file]

So basically i want it to write something in plain text, then actually add in a variable on the same line.

thanks
melefire is offline
Reply With Quote
View Public Profile
 
Old 11-16-2007, 07:41 PM Re: PHP Create File
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
get contents from file ...
do a position search for the variable .... split the text in that position.
rewrite the text to file like $part1.$insert_text.$part2
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 11-18-2007, 09:36 AM Re: PHP Create File
Arenlor's Avatar
Ultra Talker

Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
So what I understand is you want to write out something like:
$dbloc = dbloc
What you would do is:
PHP Code:
$Data '$dbloc = '."$dbloc\n"
If you write something within single quotes ' it comes out literally as you write it, useful for outputting variable names, if you put it between double quotes " it will process it though.
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-18-2007, 11:51 AM Re: PHP Create File
amw_drizz's Avatar
Ultra Talker

Posts: 301
Name: Jon
Location: New York
i would of just broke it up, but thats how i would do it,

like
PHP Code:
$data '$dbloc = ';
$data1 "$dbloc";
$data2 ";\n";
$Data $data.$data1.$data2
__________________
AMW_Drizz
Php 5.2 Mysql 4.1 IIS 6 Win2k3 Server && PHP 5.2 MySQL 4.1 Apache 2.2 (separate machine of course)
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 11-18-2007, 12:06 PM Re: PHP Create File
Arenlor's Avatar
Ultra Talker

Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
amw_drizz from now on when you want to break things up just remember this saying; The goal of a programmer's work is to reduce redundancy in their code. Bit annoying to say but it gets the point across. If you get too lazy to remember that just reduce it to say 'reduce redundancy'. It still gets the point across. That's why you use for($i = 0; $i < $num; $i++) instead of $i = 1 which would then be <= $num.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-18-2007, 12:28 PM Re: PHP Create File
amw_drizz's Avatar
Ultra Talker

Posts: 301
Name: Jon
Location: New York
the only reason why i did it that way was to get the damned installer to work, since it is working i have no reason to mess with it, and i understand what you are saying. i dislike writting long lines of code but when it dont work with the "shorter" version i had to fall back to method that i knew worked, so i ended up do it the hard way.
__________________
AMW_Drizz
Php 5.2 Mysql 4.1 IIS 6 Win2k3 Server && PHP 5.2 MySQL 4.1 Apache 2.2 (separate machine of course)
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Reply     « Reply to PHP Create File
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14903 seconds with 12 queries