PHP 5/MySQL Programming- P38

PHP 5/MySQL Programming- P38:computer programming has often been seen as a difficult and arcane skill. Programming languages are difficult and complicated, out of the typical person’s reach. However, the advent of the World Wide Web has changed that to some extent. It’s reasonably easy to build and post a Web page for the entire world to see. The language of the Web is reasonably simple, and numerous applications are available to assist in the preparation of static pages | 163 Building the Program s Main Logic The main logic for the program begins by retrieving the word list and puzzle parameters from the user s form. Then it tries to convert the list into an array. This type of text analysis is sometimes called parsing. The program then repeatedly tries to build the board until it succeeds. Once the program has successfully created the board it creates an answer key and adds the random letters with the addFoils function. Finally the program prints the completed puzzle. else get puzzle data from HTML form boardData array width width height height name name try to get a word list from user input if parseList TRUE legalBoard FALSE Chapter 5 Better Arrays and String Handling keep trying to build a board until you get a legal result while legalBoard FALSE clearBoard legalBoard fillBoard end while make the answer key key board keyPuzzle makeBoard key make the final puzzle addFoils puzzle makeBoard board print out the result page printPuzzle end parsed list if end word list exists if 164 PHP 5 MySQL Programming for the Absolute Beginner You should be able to tell the general program flow even if you don t understand exactly how things happen. The main section of a well-defined program should give you a bird s eye view of the action. Most of the details are delegated to functions. Most of the remaining chapter is devoted to explaining how these functions work. Try to make sure you ve got the basic gist of the program s flow then you see how all of it is done. Parsing the Word List One important early task involves analyzing the word list that comes from the user. The word list comes as one long string separated by newline n characters. The parseList function converts this string into an array of words. It has some other important functions too including converting each word to uppercase checking for words that do not fit in the designated puzzle size and removing unneeded carriage returns. function parseList gets word list creates array of

Không thể tạo bản xem trước, hãy bấm tải xuống
128    12    1    29-03-2023
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.