Azaz Posted July 30, 2010 Share Posted July 30, 2010 For example: I am using this code: $myFile = "newuser.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, 5); fclose($fh); echo $theData; and it displays: Bob 2 Which I am reading from my newuser.txt file! Which corresponds to the username bob, and he has the ID of 2. Now I want to make that linkable like this: <a href=.?act=Profile&id=$IDFROMTEXTFILE(2)>$NAMEFROMTEXTFILE(BOB)</a> this is possible? If so, Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/209333-extract-2-variables-from-a-text-file/ Share on other sites More sharing options...
inversesoft123 Posted July 30, 2010 Share Posted July 30, 2010 $myFile = "newuser.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, 5); fclose($fh); $pices=explode(' ', $theData); echo "<a href=\".?act=Profile&id=$pices[1]\">$pices[0]</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/209333-extract-2-variables-from-a-text-file/#findComment-1093045 Share on other sites More sharing options...
Azaz Posted July 30, 2010 Author Share Posted July 30, 2010 $myFile = "newuser.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, 5); fclose($fh); $pices=explode(' ', $theData); echo "<a href=\".?act=Profile&id=$pices[1]\">$pices[0]</a>"; Thanks!! But my id has more then 1 character it currently only shows 1 digit from my 2digit id any cause why? My id is 73, it only shows 7 hmm? Quote Link to comment https://forums.phpfreaks.com/topic/209333-extract-2-variables-from-a-text-file/#findComment-1093049 Share on other sites More sharing options...
AtlasC1 Posted July 30, 2010 Share Posted July 30, 2010 You're using fread($fh, 5); The number 5 is indicating you only want to read 5 characters, so if you count 'B', 'o', 'b', ' ', '2' that's 5 characters. It stops reading there. You might want to use fgets() instead, to read the whole line. -jm Quote Link to comment https://forums.phpfreaks.com/topic/209333-extract-2-variables-from-a-text-file/#findComment-1093175 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.