raysefo Posted June 4, 2013 Share Posted June 4, 2013 Hi,I am new to PHP.So any help would be great. I would like to display a drop down list and a textbox on a page. This dropdown data will be populated from a textbox. What I would like to know is, how to: parse a file and extact some data from a txt file which is on a server. populate this dropdown on the page with the data also I would like to display another data on the textbox according to the data selected on the drop down list and of couse how to test this script etc.Best Regards. Quote Link to comment https://forums.phpfreaks.com/topic/278745-how-to-implement-this/ Share on other sites More sharing options...
cpd Posted June 4, 2013 Share Posted June 4, 2013 (edited) http://bit.ly/16FVsoK http://bit.ly/16FVKvJ No idea what you mean for the last one. I appreciate your new but this applies to life. Go and do your own research and put the effort in yourself and you'll learn a lot more. Come back with a specific problem and we can assist. If you want to know what a specific PHP function does, go to http://php.net/function_name where function_name is any function or even something similar and it'll explain everything. To get you started on your first task: http://php.net/read http://php.net/fopen http://php.net/file_get_contents Lots of options and ways you can do it. Each one will essentially get you to 1) Open the file, 2) Loop through its contents populating the dropdown. Edited June 4, 2013 by cpd Quote Link to comment https://forums.phpfreaks.com/topic/278745-how-to-implement-this/#findComment-1433940 Share on other sites More sharing options...
raysefo Posted June 4, 2013 Author Share Posted June 4, 2013 Hi cpd, Thank you for your reply. Do I need to install something in order to work on php? or just a file editor is OK to write and run it. Best Regards. Quote Link to comment https://forums.phpfreaks.com/topic/278745-how-to-implement-this/#findComment-1433947 Share on other sites More sharing options...
cpd Posted June 4, 2013 Share Posted June 4, 2013 (edited) If you want to develop locally, which is generally what I do, you'll need to install a web server, PHP and potentially MySQL. Just get the latest releases for each; each can be found at their respective home sites. Alternatively, you can install a package such as WAMP or XAMPP although they often take a while to update so you wont necessarily have the most recent version. Edited June 4, 2013 by cpd Quote Link to comment https://forums.phpfreaks.com/topic/278745-how-to-implement-this/#findComment-1433948 Share on other sites More sharing options...
raysefo Posted June 4, 2013 Author Share Posted June 4, 2013 hi cpd, I installed WAMP and wrote some script like below; <?php $homepage = file_get_contents('d:\php\test.txt'); $kw = explode("\n", $homepage); $totalNumRow = 0; $totalAmount = 0; for($i=0;$i<count($kw);$i++){ if(substr($kw[$i], 0, 1) == "5") { echo $kw[$i]; // echo "<br>"; $totalNumRow = $totalNumRow + 1; $originalstring = $kw[$i]; $delimiter = ","; if(strpos($originalstring,$delimiter) > 0){ $outarray = explode($delimiter,$originalstring); // $variable1 = $outarray[0]; $amount = $outarray[1]; echo $amount; $totalAmount = $totalAmount + $amount; } echo "<br>"; } } echo "<br>"; echo "Total records: ".$totalNumRow; echo "<br>"; echo "Total amount: ".$totalAmount; ?> It works OK for local file. But the problem is I couldn't manage to get the contents of the file which is on FTP. Is there a way to use file_get_contents on ftp files? Best Regards. Quote Link to comment https://forums.phpfreaks.com/topic/278745-how-to-implement-this/#findComment-1433971 Share on other sites More sharing options...
boompa Posted June 4, 2013 Share Posted June 4, 2013 Yes, you give it an ftp url, like ftp://myusername:mypassword@myserver/dir/file, it should work. Quote Link to comment https://forums.phpfreaks.com/topic/278745-how-to-implement-this/#findComment-1433973 Share on other sites More sharing options...
raysefo Posted June 4, 2013 Author Share Posted June 4, 2013 But how, the port number is different (not 21). How can I add this port number to the url? Quote Link to comment https://forums.phpfreaks.com/topic/278745-how-to-implement-this/#findComment-1433974 Share on other sites More sharing options...
Solution boompa Posted June 4, 2013 Solution Share Posted June 4, 2013 ftp://myusername:mypassword@myserver:port/dir/file That should do it Quote Link to comment https://forums.phpfreaks.com/topic/278745-how-to-implement-this/#findComment-1433975 Share on other sites More sharing options...
raysefo Posted June 4, 2013 Author Share Posted June 4, 2013 (edited) thank you. Edited June 4, 2013 by raysefo Quote Link to comment https://forums.phpfreaks.com/topic/278745-how-to-implement-this/#findComment-1433976 Share on other sites More sharing options...
cpd Posted June 4, 2013 Share Posted June 4, 2013 (edited) The full URL syntax can be found at http://en.wikipedia.org/wiki/Uniform_resource_locator Edited June 4, 2013 by cpd Quote Link to comment https://forums.phpfreaks.com/topic/278745-how-to-implement-this/#findComment-1433978 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.