note 37577 added to function.strpos
| From: | jackylee at eml dot cc | Date: | Thu, 20 Nov 2003 03:17:39 +0000 |
| Subject: | note 37577 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60658@lists.php.net to get a copy of this message | ||
// 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]
*/
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37577
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37577&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37577&report=yes
Search -- http://master.php.net/manage/user-notes.php