Statistics
21
Views
0
Downloads
0
Donations
Uploader

高宏飞

Shared on 2025-12-21
Support
Share

AuthorSteven M. Schafer

I new this book was not for beginners as I have done some html programming before. However I think this book is total waste if you never done any html programming before. The content sometimes can be confusing and just today I realised there was a bug in one of the examples. If there wasnt google or reference websites like [...] I think I would really srtuggle with this book. I am refering to most of the references from w3schools and trying to get some theory from this book. I think I should of done some more search before I baught this book because I definitely think there are much better books than this.

Tags
No tags
ISBN: 0764588206
Publisher: Wrox
Publish Year: 2005
Language: 英文
Pages: 812
File Format: PDF
File Size: 12.5 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Web Standards Programmer’s Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP Steven M. Schafer 01_588206 ffirs.qxd 6/30/05 12:25 AM Page i
01_588206 ffirs.qxd 6/30/05 12:25 AM Page i
Web Standards Programmer’s Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP Steven M. Schafer 01_588206 ffirs.qxd 6/30/05 12:25 AM Page i
Web Standards Programmer’s Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2005 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN-13: 978-0-7645-8820-4 ISBN-10: 0-7645-8820-6 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 1MA/SQ/QX/QV/IN Library of Congress Cataloging-in-Publication Data: Schafer, Steven M. Web standards programmer's reference : HTML, CSS, JavaScript, Perl, Python, and PHP / Steven M. Schafer. p. cm. Includes index. ISBN-13: 978-0-7645-8820-4 (paper/website) ISBN-10: 0-7645-8820-6 (paper/website) 1. HTML (Document markup language) 2. Web site development. I. Title. QA76.76.H94S2525 2005 006.7'4--dc22 2005012600 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESEN- TATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WAR- RANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFES- SIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN THEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trade- marks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. 01_588206 ffirs.qxd 6/30/05 12:25 AM Page ii
Credits Senior Acquisitions Editor Jim Minatel Development Editor Marcia Ellett Technical Editors Bill Patterson David Schultz Dilip Thomas Production Editor Gabrielle Nabi Copy Editor Publication Services Editorial Manager Mary Beth Wakefield Vice President & Executive Group Publisher Richard Swadley Vice President and Publisher Joseph B. Wikert Project Coordinator Kristie Rees Graphics and Production Specialists Kelly Emkow April Farling Carrie A. Foster Lauren Goddard Denny Hager Jennifer Heleine Julie Trippetti Quality Control Technicians Laura Albert Leeann Harney Jessica Kramer Carl William Pierce Proofreading and Indexing TECHBOOKS Production Services 01_588206 ffirs.qxd 6/30/05 12:25 AM Page iii
About the Author Steve Schafer is a veteran of technology and publishing. He programs in several languages, works with a variety of technologies, and has been published in several technical publications and articles. He cur- rently is the COO for Progeny, an open source-based service and support company. Steve can be reached by email at sschafer@synergy-tech.com. 01_588206 ffirs.qxd 6/30/05 12:25 AM Page iv
Contents Introduction xxiii Part One: HyperText Markup Language (HTML) Chapter 1: The Basics of HTML 1 What Is the World Wide Web? 1 Creating a Web 3 HTTP: The Protocol of the Web 4 Hypertext Markup Language 7 In the Beginning — HTML 7 HTML Concept and Syntax 9 Your First Web Page 11 Summary 12 Chapter 2: Document Tags 13 Understanding Document-Level Tags 13 Document Type Tag 14 HTML Tag 15 Head Tag Section 15 Specifying the Document Title 16 Meta Tags 16 Style Section 19 Script Section 20 Body Section 20 Summary 21 Chapter 3: Paragraphs and Lines 23 Paragraphs — The Basic Block Element 23 Manual Line Breaks 25 Headings 27 Horizontal Rules 28 Preformatted Text 30 Block Divisions 31 Summary 33 02_588206 ftoc.qxd 6/30/05 12:26 AM Page v
vi Contents Chapter 4: Lists 35 Understanding Lists 35 Ordered (Numbered) Lists 37 Changing the Number Style 37 Changing the Position of the Ordinal 39 Changing the Starting Number of Ordered Lists 41 Unordered (Bulleted) Lists 42 Changing the List Item Marker 43 Changing the Position of the Ordinal 46 Definition Lists 46 Nesting Lists 47 Summary 49 Chapter 5: Images 51 Image Formats 51 Web Formats 51 Transparency 53 Interlaced and Progressive Storage and Display 54 Animation 54 Creating Images 57 Commercial Applications 57 Open Source Applications 57 Operating System Built-In Applications 58 Using Premade Images 58 Inserting Images into Web Documents 58 Image Attributes 60 Specifying Text for Nongraphical Browsers 60 Image Size 61 Image Alignment and Borders 62 Image Maps 63 Specifying an Image Map 63 Specifying Clickable Regions 64 Putting It All Together 66 Summary 67 Chapter 6: Links 69 Understanding URLs 69 Absolute versus Relative Paths 71 Using the Anchor Tag 71 Attributes of the Anchor Tag 72 Link Titles 72 02_588206 ftoc.qxd 6/30/05 12:26 AM Page vi
vii Contents Keyboard Shortcuts and Tab Orders 73 Link Colors 74 Document Relationships 75 The Link Tag 76 Summary 77 Chapter 7: Text 79 Methods of Formatting Text 79 The Font Tag 79 Inline Text Attributes 80 CSS Text Control 81 Special In-Line Text Elements 82 Nonbreaking Spaces 82 Soft Hyphens 83 Bold and Italic 84 Monospaced Text 85 Superscript, Subscript, Big, and Small Text 85 Insertions and Deletions 86 Abbreviations 87 Grouping In-Line Elements 87 Summary 88 Chapter 8: Tables 89 Parts of a Table 89 Formatting Tables 91 Table Width and Alignment 91 Cell Spacing and Padding 94 Borders and Rules 96 Rows 99 Cells 100 Captions 102 Header, Footer, and Body Sections 103 Backgrounds 105 Spanning Columns and Rows 106 Grouping Columns 109 Using Tables for Page Layout 111 Floating Page 113 Odd Graphic and Text Combinations 116 Navigational Blocks 119 Multiple Columns 120 A Word About Frames 121 Summary 122 02_588206 ftoc.qxd 6/30/05 12:26 AM Page vii
viii Contents Chapter 9: Forms 123 Understanding Forms 123 Form Handling 127 Passing Form Data 128 The Form Tag 129 The Input Tag 129 The name and id Attributes 130 Text Input Boxes 130 Password Input Boxes 131 Radio Buttons 131 Checkboxes 132 List Boxes 132 Large Text Areas 134 Hidden Fields 135 Buttons 135 Images 136 File Fields 137 Submit and Reset Buttons 137 Field Labels 138 Fieldsets and Legends 138 Tab Order and Keyboard Shortcuts 140 Preventing Changes to Fields 141 Summary 142 Chapter 10: Objects and Plugins 143 Understanding Plugins 143 The Old Way — The Embed Tag 144 The Object Tag 146 Parameters 147 Object Examples 147 Support for Older, Netscape Browsers 150 Summary 151 Chapter 11: XML 153 XML Basics 153 XML Syntax 155 XML Declaration and DOCTYPE 155 Elements 156 Attributes 157 Comments 157 02_588206 ftoc.qxd 6/30/05 12:26 AM Page viii
ix Contents Nonparsed Data 158 Entities 158 Namespaces 159 Style Sheets 159 Using XML 160 Extensible Stylesheet Language Transformations (XSLT) 161 XML Editing 161 XML Parsing 161 Summary 162 Part Two: Cascading Style Sheets (CSS) Chapter 12: CSS Basics 163 The Purpose of Styles 163 Styles and HTML 164 CSS Levels 1, 2, and 3 165 Defining Styles 166 Cascading Styles 167 Summary 169 Chapter 13: Style Definitions 171 The Style Definition Format 171 Property Values 172 Understanding Selectors 173 Matching Elements by Name 173 Matching Using the Universal Selector 174 Matching Elements by Class 174 Matching Elements by Identifier 175 Matching Elements by Specific Attributes 175 Matching Child, Descendant, and Adjacent Sibling Elements 176 Understanding Style Inheritance 179 Using Pseudoclasses 179 Anchor Styles 180 The :first-child Pseudoclass 180 The :lang Pseudoclass 181 Pseudoelements 181 :first-line 181 :first-letter 183 :before and :after 184 Shorthand Expressions 185 Summary 187 02_588206 ftoc.qxd 6/30/05 12:26 AM Page ix
x Contents Chapter 14: Text 189 Aligning Text 189 Horizontal Alignment 189 Vertical Alignment 191 Indenting Text 194 Controlling White Space 195 Floating Objects 195 The white-space Property 198 Letter and Word Spacing 198 Capitalization 200 Text Decorations 200 Formatting Lists 201 Any Element Can Be a List Item 201 The list-style-type Property 202 Positioning of Markers 203 Images as List Markers 204 Autogenerating Text 205 Define and Display Quotation Marks 205 Automatic Numbering 205 Fonts 210 Font Selection 210 Font Sizing 211 Font Styling 212 Line Spacing 213 Font Embedding 213 Summary 214 Chapter 15: Padding, Margins, and Borders 215 Understanding the CSS Box Formatting Model 215 Element Padding 218 Element Borders 219 Border Width 219 Border Style 220 Border Color 222 The Border Property Shortcut 222 Border Spacing 223 Element Margins 223 Dynamic Outlines 224 Summary 225 02_588206 ftoc.qxd 6/30/05 12:26 AM Page x
xi Contents Chapter 16: Colors and Backgrounds 227 Element Colors 227 Foreground Colors 227 Background Colors 228 Background Images 231 Repeating and Scrolling Images 232 Positioning Background Images 236 Summary 236 Chapter 17: Tables 237 CSS Properties and Table Attributes 237 Defining Borders 238 Border and Cell Spacing 239 Collapsing Borders 241 Table Layout 244 Caption Alignment and Positioning 244 Summary 244 Chapter 18: Element Positioning 245 Understanding Positioning Methods 245 Static Positioning 245 Relative Positioning 246 Absolute Positioning 248 Fixed Positioning 249 Specifying an Element’s Position 252 Floating Elements 255 Controlling an Element’s Size 256 Specifying an Exact Size 257 Specifying a Minimum or Maximum Size 257 Controlling Overflow 257 Element Layers 258 Controlling Visibility 261 Summary 262 Part Three: JavaScript and DHTML Chapter 19: JavaScript Basics 263 History of JavaScript 263 Different Implementations 264 02_588206 ftoc.qxd 6/30/05 12:26 AM Page xi
xii Contents Determining the Document Object Model 264 Uses for JavaScript 265 Incorporating JavaScript in Your Documents 266 Anatomy of the <script> Tag 266 Placement of the Script Tag 267 Execution of Scripts 267 Summary 268 Chapter 20: The JavaScript Language 269 Basic JavaScript Syntax 269 Data Types and Variables 270 Data Types 270 Variables 271 Calculations and Operators 272 Control Structures 274 Do While 274 While 274 For and For In 275 If Else 276 Switch 277 Break and Continue 278 Labels 278 Built-in Functions 279 User-Defined Functions 280 Objects 281 Built-in Objects 282 User-Created Objects 283 Event Handling 284 JavaScript Errors and Troubleshooting 286 Using the Right Tools 287 Common JavaScript Syntactical Mistakes 287 Identifying Problems 288 Summary 290 Chapter 21: The Document Object Model 291 The History of the DOM 291 Understanding the Document Object Model 292 DOM Node Properties and Methods 295 Traversing a Document’s Nodes 296 Changing Nodes 302 Summary 310 02_588206 ftoc.qxd 6/30/05 12:26 AM Page xii
xiii Contents Chapter 22: JavaScript Objects and Dynamic HTML 311 Built-in JavaScript Objects 311 Window Object 311 Document Object 312 Form Object 313 Location Object 314 History Object 315 The Self Object 315 Accessing an Element by Its ID 316 Dynamic HTML 316 Summary 322 Chapter 23: Using JavaScript 323 How and When to Use JavaScript 323 The Case Against Using JavaScript 323 Guidelines for Using JavaScript 324 JavaScript Resources 324 JavaScript Examples 325 Writing Text to a Document 325 Using Other Windows 329 Images 333 Working with Forms 341 Dynamic HTML Tricks 347 Summary 361 Part Four: Common Gateway Interface (CGI) Chapter 24: CGI Basics 363 CGI History and Operation 363 Understanding HTTP Request and Response 363 HTTP Data Encapsulation 364 How CGI Works 366 Serving CGI 367 A Simple CGI Example 368 Summary 370 Chapter 25: Perl Language 371 The History of Perl 371 Additional Perl Resources 371 02_588206 ftoc.qxd 6/30/05 12:26 AM Page xiii
xiv Contents Basic Perl Syntax 372 Data Types and Variables 372 Data Types 372 Variables 373 Special Variables 374 Calculations and Operators 377 Control Structures 380 While and Until 380 For 380 Foreach 381 If Else 381 More Loop Control — Continue, Next, Last, Redo 382 Regular Expressions 383 Regular Expression Operations 383 Regex Special Characters 384 Example Expressions 385 Modifying Expressions 385 Memorizing Substrings 386 Built-in Functions 386 User-Defined Functions 387 File Operations 387 Standard Operating Procedure 388 Opening a File 388 Reading from a Text File 388 Writing to a Text File 389 Closing a File 389 Working with Binary Files 389 Getting File Information 390 Other File Functions 391 Objects 391 Perl’s Object Nomenclature 391 Perl Constructors 392 Accessing Property Values 392 Modules 393 Using Perl for CGI 393 Perl Errors and Troubleshooting 394 Maximum Error Reporting 394 The Apache Internal Server Error Message 395 Summary 396 02_588206 ftoc.qxd 6/30/05 12:26 AM Page xiv
xv Contents Chapter 26: The Python Language 397 The History of Python 397 Additional Python Resources 398 Modules 398 Python Interpreter 398 Basic Python Syntax 400 Data Types and Variables 400 Data Types 400 1077685140Variables 407 Variable Scope 407 Calculations and Operators 408 Control Structures 410 While Loop 410 For Loop 411 If Statement 411 Try Statement 412 More Loop Control — Continue, Break 412 Regular Expressions 413 Regular Expression Operations 414 Regex Special Characters 414 Built-in Functions 415 User-Defined Functions 416 Lamda Functions 417 File Operations 417 Standard Operating Procedure 417 Opening a File 417 Reading From a Text File 418 Writing to a Text File 419 Closing a File 420 Working with Binary Files 420 Objects 420 Python Errors and Exception Handling 421 Troubleshooting in Python 421 Run the Code in the Interpreter 421 Using the cgitb Module 421 Redirecting the Error Stream 422 Summary 422 02_588206 ftoc.qxd 6/30/05 12:26 AM Page xv
xvi Contents Chapter 27: Scripting with Other Executable Code 423 Requirements for CGI 423 Sample CGI Using Bash Shell Scripting 424 Configuring Apache to Deliver Bash Scripts 424 Getting Data into the Script 425 Getting Data Out of the Script 426 Doing Useful Things 428 Summary 430 Chapter 28: Using CGI 431 How and When to Use CGI 431 Sample Data 432 Sample Form 432 Sample MySQL Data 434 Perl Examples 439 Date and Time Handling 439 Handling Form Data 444 Using Form Data 447 Accessing Databases 453 Python Examples 457 Date and Time Handling 457 Handling Form Data 460 Using Form Data 463 Accessing Databases 467 Summary 469 Part Five: PHP Chapter 29: PHP Basics 471 The History of PHP 471 Requirements for PHP 472 PHP Fundamentals 473 PHP Beginning and Ending Tags 473 Command Termination Character and Blocks of Code 474 PHP’s Use of White Space 474 Commenting Code 474 PHP Variables 475 A Sample PHP Script 475 Summary 477 02_588206 ftoc.qxd 6/30/05 12:26 AM Page xvi
xvii Contents Chapter 30: The PHP Language 479 Calculations and Operators 479 Control Structures 482 Do-while 482 While 482 For 482 Foreach 483 If Else 484 Switch 485 Break and Continue 486 Built-in PHP Functions 486 User-Defined Functions 490 Return Values 490 Arguments 490 Variable Scope 491 Objects 491 Class Definitions 491 Constructors and Destructors 491 Methods and Properties 492 Working with Objects 493 Additional Object Conventions 494 File Operations 495 Opening a File 495 Reading Text from a File 496 Writing Text to a File 497 Closing a File 497 Working with Binary Files 497 Locking Files 499 Other File Functions 499 PHP Errors and Troubleshooting 500 Use the Right Tools 500 Avoiding Common Syntactical Mistakes 501 Identifying Problems 502 Error Control and Processing 503 Summary 506 Chapter 31: Using PHP 507 How and When to Use PHP 507 PHP Resources 508 02_588206 ftoc.qxd 6/30/05 12:26 AM Page xvii
xviii Contents PHP Examples 509 Date and Time Handling 509 Handling Form Data 514 Using Form Data 517 Accessing Databases 523 Summary 526 Part Six: Appendixes Appendix A: XHTML Reference 527 Element Listings 528 Event Attributes 570 Standard Events 570 Other Events 571 Other Common Attributes 571 Core Attributes 571 Internationalization Attributes 571 Common Color Codes 571 Appendix B: CSS Properties 577 Selector Examples 577 Property Listings 578 Background 578 List 580 Generated Content 581 Font and Text 582 Text Direction 587 Block 588 Positioning 591 Borders 594 Table 596 Printing 598 Miscellaneous 599 Selector Review 600 Name Matching 600 Attribute Matching 600 Position Matching 600 Pseudo-classes 601 Pseudo-elements 601 02_588206 ftoc.qxd 6/30/05 12:26 AM Page xviii
The above is a preview of the first 20 pages. Register to read the complete e-book.