Jump to content

Problem with String...


iyeru42

Recommended Posts

PHP gives the error...

	$fh = fopen("../includes/dbinfo.inc.php", "w");	if ($fh==false) {		die("unable to create ../includes/dbinfo.inc.php. Make sure the includes directory within the forum root dir is CHMOD to 0777.");	} else {	$strWriteData = "<?php\n$aDBInfo['type'] = '".$aDBInfo['type']."';\n$aDBInfo['address'] = '".$aDBInfo['address']."';\n$aDBInfo['username'] = '".$aDBInfo['username']."';\n$aDBInfo['password'] = '".$aDBInfo['password']."';\n$aDBInfo['database'] = '".$aDBInfo['database']."';\n$aDBInfo['email'] = '".$aDBInfo['email']."';\n?>";	fwrite($fh, $strWriteData);	fclose($fh);	}

How do I make it so I can still write this? (I need the line breaks in the destination file, so I cannot remove the \ns, and I cannot remove the variables that are inside the strings nor the beginning and ending <?php and ?>)

Link to comment
Share on other sites

Change it to this and see if it helps. (BTW, this should be faster and easier to read than the above.)

$strWriteData = "<?php\n\$aDBInfo['type'] = '{$aDBInfo['type']}';\n\$aDBInfo['address'] = '{$aDBInfo['address']}';\n\$aDBInfo['username'] = '{$aDBInfo['username']}';\n\$aDBInfo['password'] = '{$aDBInfo['password']}';\n\$aDBInfo['database'] = '{$aDBInfo['database']}';\n\$aDBInfo['email'] = '{$aDBInfo['email']}';\n?>";

I escaped the $s and used string parsing rather than concatenation.You might also be interested in heredocs.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...