Web Data Management 152-155 PHP Functions and Include Files Notes Activity Quick Links & Text References Pages 390 391 – Pages 390 393 – 394 395 – Pages 76 77 – Pages 164 165 – Pages 390 393 – Pages 162 163 – 380 381 – Pages 382 383 – Pages 384 385 – Pages 386 387 – Pages 388 389 – Locations Can actually be placed anywhere (inside php tags) Even the tag </html> Best stored in external files (libraries, most common) Function Libraries Create a weights.php Model file PHP functions stored in a separate file (.php extension) File must include begin and end php tags BIG IMPORTANT NOTE: Do not include any whitespace before the <?php or after the ?>. Localhost deals with them OK, but real web Add require statement to servers get confused by the extra spaces. weightCases Functions only. No HTML unless created by PHP (echo) To in your web page: include Remove from cases. require('model/myLibrary.php'); There is also a statement. Larger web require_once Note errors (require?) sites may include libraries where the libraries include other libraries. A function may only be included once. If you try to include (require) it again, you’ll get an error. Murach recommends using unless you run require into trouble.
Web Data Management 152-155 PHP Functions and Include Files Notes Activity Quick Links & Text References Pages 390 – 391 Pages 390 – 393 394 – 395 Pages 76 – 77 Pages 164 – 165 Pages 390 – 393 Pages 162 – 163 380 – 381 Pages 382 – 383 Pages 384 – 385 Pages 386 – 387 Pages 388 – 389 Locations Can actually be placed anywhere (inside php tags) Even the </html> tag Best stored in external files (libraries, most common) Function Libraries PHP functions stored in a separate file (.php extension) File must include begin and end php tags BIG IMPORTANT NOTE: Do not include any whitespace before the <?php or after the ?>. Localhost deals with them OK, but real web servers get confused by the extra spaces. Functions only. No HTML unless created by PHP (echo) To include in your web page: require('model/myLibrary.php'); There is also a require_once statement. Larger web sites may include libraries where the libraries include other libraries. A function may only be included once. If you try to include (require) it again, you’ll get an error. Murach recommends using require unless you run into trouble. Create a weights.php Model file Add require statement to weightCases Remove from cases. Note errors (require?)