Replace numbers with a sequence in PHP ising Vim or Geany
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What I want to do is extend what I have up to 100 without having to copy and paste what I have got and then manually replace the numbers up to 100. I realise that I will have to manually insert the correct answer for all 100 questions as there is no pattern to the answers.
I'm really in the dark here. I don't know whether this is something that can be achieved within Vim or whether I need to use a script or another tool.
Thanks NevemTeve. If I understand correctly (which I probably don't : this is all very new to me ) the code you have given me improves what I have done so far but I am not sure it answers my question. I really want to extend the answers to 100. The actual correct answers - A, B, C and D - do not follow a regular, predictable pattern and I will have to input them manually and individually. There will be more than one multiple choice test (of 100 questions) using the same come to "mark" the test.
Ideally, to generalise the solution (to create the PHP) you should store the questions, the answer choices and right solution in a data base and use a loop to create the PHP file.
This way you can key in the100 data sets (consisting of question, answer choices and right answer) off line ie. at your own pace into say a simple text file. Then write a small script (I prefer awk) to generate what ever code you want.
IN MY VIEW THIS WOULD SOLVE YOUR MAJOR PROBLEM OF REPEATEDLY ENTERING, CORRECTING AND VERIFYING THE INTEGRITY OF THE PHP STRUCTURE USING VIM.
You could then mail this PHP file off to others to use.
Another solution once you have the question bank ready would be write a PHP programme that reads the data and renders the page. You obviously know this. Of course this requires access to a personal or test web server that eders PHP onto the browser.
Thanks NevemTeve - that really did the trick. Everything now works as it should. It's amazing how just seeing the right code at the right time can open up a whole new world. I've been playing with this array since you posted it and I really feel as though I have learned something. Cheers!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.