Files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Files

Post by Silver_Eclipse »

Code: Select all

$templateFile = "$boarddir/template.php";
	if (!file_exists($templateFile))
	$templateFile = "$boarddir/template.html";

	$file = fopen($templateFile,"r");
	$fulltemplate = fread($file,filesize($templateFile));

	$fulltemplate = preg_replace(".admin_color {
  COLOR: (.*);}.gm_color {
  COLOR: (.*);}.developer_color {
  COLOR: (.*);}.modteam_color {
  COLOR: (.*);}.users_color {
  COLOR: (.*);}",".admin_color {
  COLOR: {HTTP_POST_VARSї'admin_usercolor']};}.gm_color {
  COLOR: {HTTP_POST_VARSї'globalmod_usercolor']};}.developer_color {
  COLOR: {HTTP_POST_VARSї'developer_usercolor']};}.modteam_color {
  COLOR: {HTTP_POST_VARSї'mod_usercolor']};}.users_color {
  COLOR: {HTTP_POST_VARSї'users_usercolor']};}",$fulltemplate);

	$fh = fopen($boarddir/template.php,'w');
	fputs ($fh,$fulltemplate);
	fclose($fh);
can someone please tell me what is wrong with this code, i have been editing it over and over and it still doesnt work right. Thanks.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try putting a $ infront of all the HTTP_POST_VARS

and escape the {'s (unless they are supposed to be there for literals)
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Post by Silver_Eclipse »

*smacks himself* how could i forget the $'s doh thanks i'll try that
Edit: Still doesnt work
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Post by Silver_Eclipse »

also those {'s that arent around the $HTTP_POST_VARS are part of the pattern that i'm trying to replace(the file has css in it)
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try something like...

Code: Select all

$exps = array(
  "1" => "(\.admin_color \{ COLOR: )(.*)(;\})",
  "2" => "(\.gm_color \{ COLOR: )(.*)(;\})",
  "3" => "(\.developer_color \{ COLOR: )(.*)(;\})",
  "4" => "(\.modteam_color \{ COLOR: )(.*)(;\})",
  "5" => "(\.users_color \{ COLOR: )(.*)(;\})"
  );

  $reps = array(
  "1" => "\\1{$HTTP_POST_VARSї'admin_usercolor']}\\3",
  "2" => "\\1{$HTTP_POST_VARSї'globalmod_usercolor']}\\3",
  "3" => "\\1{$HTTP_POST_VARSї'developer_usercolor']}\\3",
  "4" => "\\1{$HTTP_POST_VARSї'mod_usercolor']}\\3",
  "5" => "\\1{$HTTP_POST_VARSї'users_usercolor']}\\3"
  );

  $fulltemplate = preg_replace($exps, $reps, $fulltemplate);
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Post by Silver_Eclipse »

in:

Code: Select all

"1" => "\\1{$HTTP_POST_VARSї'admin_usercolor']}\\3",
what is the \\1 and \\3 for? also the (.*) sould be the only thing replaced by the variables the rest needs to be put back in.(also i tried it and still doesnt work and i have no idea why, i always have trouble with changeing flat files.
Post Reply