Niss3 Posted October 17, 2022 Share Posted October 17, 2022 Hello! I am a beginner in PHP and made a simple quiz page. I named the quiz questions 1.php 2.php 3.php and so on to make coding simple when loading next question. Now when I am done I wanted to "clean" things up. So I tried putting all the questions in a folder. That turned out to be a problem though. When I use; include(foldername\1.php); The file is not loaded. It works fine if I put it back in the main directory. After some error-searching I tried using letters instead of numbers, so I renamed 1.php to a.php and then suddenly it worked. I really would like to keep the filenames as numbers, so if anyone here could help me figure out how to allow single digit number php files in a folder with the include command, please do! Thank you very much! Quote Link to comment Share on other sites More sharing options...
Solution ginerjm Posted October 17, 2022 Solution Share Posted October 17, 2022 Basically it's telling you that there rules to filenaming. What's wrong with naming them 'page1.php' and 'page2.php'? Too hard to program? Quote Link to comment Share on other sites More sharing options...
Niss3 Posted October 17, 2022 Author Share Posted October 17, 2022 12 minutes ago, ginerjm said: Basically it's telling you that there rules to filenaming. What's wrong with naming them 'page1.php' and 'page2.php'? Too hard to program? I didn't think of that, thanks! I did a quick test but it appears I have made some other misstake now. I will try again tomorrow and return here with the sollution I came up with, but I will definitly try to add a prefix to the files! Quote Link to comment Share on other sites More sharing options...
requinix Posted October 17, 2022 Share Posted October 17, 2022 Actually what it's telling you is that \1 in a double-quoted string does something special... Quote Link to comment Share on other sites More sharing options...
Niss3 Posted October 17, 2022 Author Share Posted October 17, 2022 $filn=("f\aquick".$spelb); include($filn.".php"); This is the sollution I came up with. Using include("path".$variable."filending") didnt work so I made some of it into a variable and it worked! I have no idea what the double quote string thingy is. It did not accept "fraga" as filename either, so I guess it is complex when putting files in folders. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 17, 2022 Share Posted October 17, 2022 What is the backslash for? What are the parens for? // determine what number to use in the name and assign it. $i = GetNextFilNum(); // call a function that returns a number $filename = "file$i.php"; include $filename; Quote Link to comment 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.