Php example by example
B
PHP
Y E X A M P L
E
201 West 103rd Street Indianapolis, Indiana 46290
Toby Butzon
PHP By Example
Copyright© 2002 by Que
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permissionfrom the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein. International Standard Book Number:0-7897-2568-1 Library of Congress Catalog Card Number: 2001090370 Printed in the United States of America First Printing: November 2001 04 03 02 01 4 3 2 1
Associate Publisher
Dean Miller
Senior Acquisitions Editor
Jenny L. Watson
Development Editor
Sean Dixon
Technical Editor
Robert Grieger
Managing Editor
Thomas F. Hayes
Project Editor
Karen S. Shields
Indexer
ChrisBarrick
Proofreaders
Bob LaRoche Jeannie Smith
Team Coordinator
Cindy Teeters
Trademarks
All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Que cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.
InteriorDesigner
Karen Ruggles
Cover Designer
Rader Design
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising fromthe information contained in this book.
iii
Contents at a Glance
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Part I Getting Started with Programming in PHP 5 1 Welcome to PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 2 Variables and Constants . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . .28 3 Program Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48 4 Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70 5 String Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88 113 . . . . . . . . . . . . . . . . . . . . . .114 . . . . . . . . . . . . . . . . . . . . ..136 . . . . . . . . . . . . . . . . . . . . . .152 . . . . . . . . . . . . . . . . . . . . . .170
Part II Control Structures 6 The if, elseif, and else Statements 7 The switch Statement . . . . . . . . . . . 8 Using while and do-while . . . . . . . . 9 Using for and foreach . . . . . . . . . . .
Part III Organization and Optimization of Your Program 185 10 Functions . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .186 11 Classes and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .214 12 Using Include Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .240 Part IV Advanced PHP Features 13 Creating Dynamic Content with PHP and a MySQL Database . . . . . . . . . . . . . . . . . . . . . . . . 14Using PHP for Password Protection . . . . . . . 15 Allowing Visitors to Upload Files . . . . . . . . . 16 Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Putting It All Together . . . . . . . . . . . . . . . . . 261 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .262 .292...
Regístrate para leer el documento completo.