note 19677 added to function.fscanf
| From: | gozer at fanhunter dot com | Date: | Thu, 07 Mar 2002 11:53:40 +0000 |
| Subject: | note 19677 added to function.fscanf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27464@lists.php.net to get a copy of this message | ||
Hi,
A few days ago we got multiple mySQL crashes due to a hardware failure and other processes running.
While we thought it could be the mySQL daemon overloaded, we started looking for alternate ways to
get our little databases working so we started using fscanf to parse files.
We ran into multiple problems due to the whitespace and other characters that were in our database.
Finally, we made it to work using sets as james@zephyr-works.com remarked.
Our final function is:
function get_sections($include_dir){
$filename = $include_dir . "sections.dat.php";
$datafile = fopen ($filename ,"r");
while ($sectioninfo = fscanf ($datafile, "%[0-9]|%[a-zA-Z0-9@&;:,.
/!?-]|%[a-zA-Z0-9@&;:,. /!?-]|%[a-zA-Z]|%[a-zA-Z0-9@/?&;.+=-]|%[0-9]|%[0-9]|%[0-9]\n"))
{
list($id, $name, $description, $language, $directory, $id_uplevel, $order, $hassubsection) =
$sectioninfo;
// Show output
echo $id . "-" . $name. "-" . $description . "-" . $language .
"-" . $directory . "-" . $id_uplevel . "-" . $order . "-" .
$hassubsection . "<br>\n";
}
fclose($datafile);
}
The contents of sections.dat.php (for example):
1|home|Página principal de Fanhunter.|castellano|==|0|0|0
2|fanhunter|Sección principal dedicada al universo Fanhunter.|castellano|fanhunter/|1|0|0
3|outfan|Sección principal dedicada al universo Outfan.|castellano|outfan/|1|0|0
4|fanpiro|Sección principal dedicada al universo Fanpiro.|castellano|fanpiro/|1|0|0
5|tienda|La tienda de Fanhunter.|castellano|tienda/|1|0|0
6|the zone|Sección principal Miscelánea.|castellano|thezone/|1|0|0
7|flfcn|Sección principal dedicada a Fan Letal/Fan con Nata.|castellano|fanletal/|1|0|0
8|foro|Nuestro foro de discusión.|castellano|foro/|1|0|0
9|chat|Sección para chatear.|castellano|chat/|1|0|0
10|links|Sección recopilatoria de enlaces de interés a otras
páginas.|castellano|links/|1|0|0
Note: The '==' in directory means no directory needed to be specified.
Pay attention to linebreaks, as this forum puts some of them into the code I pasted.
Good luck guys.
--
http://www.php.net/manual/en/function.fscanf.php
http://master.php.net/manage/user-notes.php?action=edit+19677
http://master.php.net/manage/user-notes.php?action=delete+19677
http://master.php.net/manage/user-notes.php?action=reject+19677