A problem in PHP?

<font color="$color">红色</font> code above saved as "index.html", then <?php $color = "red"; $file="index.html"; $fp = fopen($file,"r"); $text = file_get_contents($file); echo $text; /* I hope the color of the $text is red set in $color ; */ fclose($fp) ?> code above saved as "test.php". then checking it. I hope the color of the $text is red set in $color ; But I couldn't get the effect I hope for. who would tell me why and how to ?

Public Comments

  1. You need to change the line echo $text; to echo "<font color='$color'>" + text + "</font>";
  2. ekuu this link will help http://www.barelyfitz.com/projects/csscolor/ http://www.php-scripts.com/php_diary/121999.html http://www.codewalkers.com/c/a/GUI-Code/Change-Background-Color-each-day/
  3. It's because using file_get_contents() will output a string. Echoing this string will literally output it, not change variables.. You could do this.. index.html: <font color="$color">红色</font> change.php <?php $color = "red"; $file="index.html"; $fp = fopen($file,"r"); $text = file_get_contents($file); //This is the thing: $text = str_replace("$color", $color, $text); echo $text; fclose($fp) ?>
  4. <?php $color = "FF0000"; // this is red! $file="index.html"; $fp = fopen($file,"r"); $text = file_get_contents($file); echo "<font color='#" . $color . "'>" . $text . "</font>"; fclose($fp) ?>
Powered by Yahoo! Answers