note 37577 deleted from function.strpos by tularis
| From: | tularis@php.net | Date: | Wed, 22 Aug 2007 13:27:50 +0000 |
| Subject: | note 37577 deleted from function.strpos by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-129703@lists.php.net to get a copy of this message | ||
Note Submitter: jackylee at eml dot cc
----
enough to search and replace a new string into a text file.
hope this can save your time :-)
original config.txt file:
Current Background = [wallpaper/WinXP.jpg]
Last Time = [20]
<?php
$var = file_get_contents("data/config.txt");
$out = fopen("data/config.txt", "w");
$var2 = writeConfig($var , "Current Background = [" , "]" ,
"wallpaper/Bgred.jpg");
$var2 = writeConfig($var2, "Last Time = [" , "]" , "21");
fwrite($out, $var2);
fclose($out);
function writeConfig($var, $begString, $endString, $newString)
{
$begPos = strpos($var,$begString) +strlen($begString);
$endPos = strpos($var , $endString , $begPos);
$result = substr($var, 0, $begPos);
$result .= $newString;
$result .= substr($var, $endPos);
return $result;
}
?>
changed config.txt file:
Current Background = [wallpaper/Bgred.jpg]
Last Time = [21]