Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

fscanf not parsing all values

fscanf string problem



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';
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>";

my file content
Gear Gear1 
History history


2:09 pm on Jul 19, 2012 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

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).


2:56 pm on Jul 24, 2012 (gmt 0)

dfeddel wrote:

Try changing
(single quotes to double quotes).

A single-quoted string [php.net] in PHP is a literal string. That means, in your current code,
is looking for, literally, a "\" followed by a "t" instead if the tab character.


Featured Threads

Hot Threads This Week

Hot Threads This Month