mra Posted December 5, 2006 Share Posted December 5, 2006 hi ive got a code but its not working it meant to pick out 3 names with their drinks out of 20 names and drinks but it doesnt seem to print out this is wat ive done so far<?php$page = file(‘drinkz.txt’);print "Jim, Peter, Abigail" Link to comment https://forums.phpfreaks.com/topic/29515-print-names/ Share on other sites More sharing options...
obsidian Posted December 5, 2006 Share Posted December 5, 2006 [quote author=mra link=topic=117418.msg479024#msg479024 date=1165322052]hi ive got a code but its not working it meant to pick out 3 names with their drinks out of 20 names and drinks but it doesnt seem to print out this is wat ive done so far<?php$page = file(‘drinkz.txt’);print "Jim, Peter, Abigail"[/quote]What you have so far is going to pull the text of "drinkz.txt" in as an array, but then, you're not doing anything with it. What is the structure of your "drinkz.txt" file? If we know that, we'll be able to better help you pull what you're after. A print statement simply prints out what is in your string, so you'll get "Jim, Peter, Abigail" out on the screen. Link to comment https://forums.phpfreaks.com/topic/29515-print-names/#findComment-135428 Share on other sites More sharing options...
wata Posted December 5, 2006 Share Posted December 5, 2006 so how exactly am i ment to print out the names this is first time im doing this so could u be more basic to me please Link to comment https://forums.phpfreaks.com/topic/29515-print-names/#findComment-135432 Share on other sites More sharing options...
obsidian Posted December 5, 2006 Share Posted December 5, 2006 As I said, we must know the layout of your "drinkz.txt" file before we can help you print out the names. Can you give us an example of how your file is laid out? Link to comment https://forums.phpfreaks.com/topic/29515-print-names/#findComment-135434 Share on other sites More sharing options...
wata Posted December 5, 2006 Share Posted December 5, 2006 the drinks are in a list e.g. mra, cokemrb, fantaetcthis is wat ive done so far now<?php$lines = file(‘drinks.txt’);$n=0while($n<sizeof($lines)) {$searchlines=$lines[$n];print "searchline <br>";$n=$n+1; Link to comment https://forums.phpfreaks.com/topic/29515-print-names/#findComment-135435 Share on other sites More sharing options...
wata Posted December 5, 2006 Share Posted December 5, 2006 any one?????????????????? Link to comment https://forums.phpfreaks.com/topic/29515-print-names/#findComment-135446 Share on other sites More sharing options...
craygo Posted December 5, 2006 Share Posted December 5, 2006 ok, help us out here by copying and pasting a few lines of the text file. we cannot help without the format of the file.Ray Link to comment https://forums.phpfreaks.com/topic/29515-print-names/#findComment-135447 Share on other sites More sharing options...
wata Posted December 5, 2006 Share Posted December 5, 2006 these are the names in a txt file and i wanna print out only jim, Peter and AbigailDilal,cokeHaleema,fantaNosheen,tangoWaseem,cokeRabi,pepsiVaseem,tangoLuke,fantaNoreen,cokePeter,pepsiChristopher,tangoJim,cokeEbrahim,fanta Sambo,fantaAndrew,pepsiAbigail,colaKemal,tango Link to comment https://forums.phpfreaks.com/topic/29515-print-names/#findComment-135450 Share on other sites More sharing options...
craygo Posted December 5, 2006 Share Posted December 5, 2006 ok here is something you could use[code]<?php// read file into an array$lines = file('drinks.txt');// create array for new data$data=array();// loop through each lineforeach($lines as $val){// break up each line by the comma$line = explode(",", $val);// make name the key and the drink the value$data[$line[0]] = $line[1];}// now you have an array called data now you can use is any way you likeforeach($data as $name => $drink){echo "$name: $drink<br>\n";}?>[/code]Ray Link to comment https://forums.phpfreaks.com/topic/29515-print-names/#findComment-135458 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.