| fscanf not parsing all values fscanf string problem |
dfedde

msg:4476950 | 1:17 am on Jul 19, 2012 (gmt 0) | I am new to php. I am trying to make my navigation for my page generate from files that are easy editable by my partner that types all the content for this site. I created a test file and am trying to parse it with fscanf but I can not get it to parse the second value on each line only the first is grabbed my code
<?php // takes all the tasks in content files in a folder and prints them as links $dir = "content/"; $page = $_GET['page']; if (!is_file($dir.$page.".menu")) { $page = 'def'; } $menu_handle=fopen($dir.$page.".menu","r"); while(list($name,$call)=fscanf($menu_handle,'%s\t%s\n')){//only name is grabbed echo $call,$name;\\debug echo echo "<a class='nav' href='?page=".$call."'>".$name."</a>"; } fclose($menu_handle);
my file content
Gear Gear1 History history
|
eelixduppy

msg:4477130 | 2:09 pm on Jul 19, 2012 (gmt 0) | I'd put money on your file not being properly formatted. Use a text editor where you can show the hidden characters to make sure... I am trying to make my navigation for my page generate from files |
| Are you caching this in any way? It would be kind of expensive to parse a text file for every page request. You should also probably look into template engines (e.g., Smarty).
|
rlange

msg:4478434 | 2:56 pm on Jul 24, 2012 (gmt 0) | dfeddel wrote:
fscanf($menu_handle,'%s\t%s\n') |
| Try changing '%s\t%s\n' to "%s\t%s\n" (single quotes to double quotes). A single-quoted string [php.net] in PHP is a literal string. That means, in your current code, fscanf() is looking for, literally, a "\" followed by a "t" instead if the tab character. -- Ryan
|
|
|