note 19677 deleted from function.fscanf by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 09:00:55 +0000 |
| Subject: | note 19677 deleted from function.fscanf by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196822@lists.php.net to get a copy of this message | ||
Note Submitter: gozer at fanhunter dot com
----
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.