PHP Basics for Designers

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    PHP Basics for Designers - Presentation Transcript

    1. PHP Basics for Designers
        • Matthew Turland
        • Atlanta Web Designers Group
        • November 11, 2008
    2. So what is PHP?
        • A programming language.
        • Mainly intended for web applications.
        • Also useful for other things.
        • That last part is another story for another time...
    3. Let's jump right in...
        • These do the same thing.
        • <p>Hello world!</p>
        • <p> <?php echo 'Hello world!'; ?> </p>
    4. How is that useful?
        • When 'Hello world!' could be anything.
        • <?php $title = 'Goodbye cruel world!'; ?>
        • ...
        • <p> <?php echo $title; ?> </p>
        • Result : <p>Goodbye cruel world!</p>
    5. Can you break that down?
        • <?php $title = 'Goodbye cruel world!'; ?>
      opening PHP tag variable assignment operator string (quote to quote) closing PHP tag end of statement
    6. A little shorter, maybe?
        • These do the same thing.
        • <p> <?php echo $title; ?> </p>
        • <p> <?= $title ?> </p>
        • For #2, short_open_tag must be on.
    7. Now you see me...
        • The HTML here is displayed.
        • <?php $sidebar = true; ?>
        • ...
        • <?php if ($sidebar): ?>
        • <ul>
        • ...
        • </ul>
        • <?php endif; ?>
    8. ... and now you don't.
        • The HTML here is not displayed.
        • <?php $sidebar = false ; ?>
        • ...
        • <?php if ($sidebar): ?>
        • <ul>
        • ...
        • </ul>
        • <?php endif; ?>
      Here's why
    9. On one condition...
        • <?php if ($page == 'home'): ?>
        • <ul>
        • ...
        • </ul>
        • <?php endif; ?>
      comparison operator == for “is” != for “is not”
    10. Playing with strings
        • These all result in the same output.
        • echo 'Hello' . ' ' . 'world!';
        • $greeting = 'Hello';
        • echo $greeting . ' ' . 'world!';
        • $object = 'world';
        • echo $greeting . ' ' . $object . '!';
      concatenation operator (combines strings)
    11. Building strings
        • These do the same thing.
        • $greeting = 'Hello';
        • $greeting = $greeting . ' world!';
        • $greeting = 'Hello';
        • $greeting .= ' world!';
    12. All for one...
        • Your standard HTML list.
        • <ul>
        • <li>Milk</li>
        • <li>Eggs</li>
        • ...
        • <li>Bread</li>
        • </ul>
    13. ... one for all.
        • The same list of items in PHP.
        • <?php $list = array( 'Milk', 'Eggs', ... , 'Bread'); ?>
        • ...
        • <ul>
        • <?php foreach ($list as $item): ?>
        • <li> <?php echo $item; ?> </li>
        • <?php endforeach; ?>
        • </ul>
    14. Adding a dimension...
        • <?php
        • $links = array(
        • array(
        • 'text' => 'Exciting new headline',
        • 'href' => '/exciting-new-headline'
        • ),
        • array(
        • 'text' => 'News from yesterday',
        • 'href' => '/news-from-yesterday'
        • )
        • );
        • ?>
      “ row” “ column” key value
    15. ... and displaying it.
        • <ul>
        • <?php foreach ($links as $link): ?>
        • <li><a href=” <?php echo $link['href']; ?> ”>
        • <?php echo $link['text']; ?> </a></li>
        • <?php endforeach; ?>
        • </ul>
    16. The results are in!
        • <ul>
        • <li><a href=” /exciting-new-headline ”> Exciting New Headline </a></li>
        • <li><a href=” /news-from-yesterday ”> News from yesterday </a></li>
        • </ul>
    17. The not-so-great wall
        • http://example.com/foo.php?title=<script>...
        • <p> <?= $_GET['title'] ?> </p>
        • Result : <p><script>...</p>
        • Most likely, this is not good for security.
    18. The great escape
        • http://example.com/foo.php?title=<script>...
        • <p> <?= htmlspecialchars($_GET['title']) ?> </p>
        • Result : <p>&lt;script&gt;...</p>
        • Rendered result: <script>
    19. Stylish yet functional
        • Functions are reusable bits of code.
        • function ul($items) {
        • $result = '<ul>';
        • foreach ($items as $item) {
        • $result .= '<li>' . htmlspecialchars($item) . '</li>';
        • }
        • return $result . '</ul>';
        • }
    20. Call me
        • This...
        • <?= ul(array('Milk', 'Eggs', 'Bread')) ?>
        • ... becomes this...
        • <ul><li>Milk</li><li>Eggs</li><li>Bread</li></ul>
    21. Plug and play <?php include 'header.html'; ?> <?php include 'navigation.php'; ?> Content <?php include 'footer.html'; ?> <?php include 'sidebar.html'; ?>
    22. Want to learn more?
        • http://php.net/manual/en
        • http://phpcommunity.org
        • irc://irc.freenode.net/phpc
        • http://phpwomen.org
        • irc://irc.freenode.net/phpwomen
        • http://phpbuilder.com/board
        • http://www.amazon.com/dp/0596005601
    23. To sum it up...
        • Avoid copy and paste. Includes and functions!
        • Before outputting variables, escape them!
        • PHP has lots of built-in functions. Use them!
        • Don't let your learning about PHP stop here!
    24. Questions?

    + tobias382tobias382, 2 years ago

    custom

    1652 views, 0 favs, 3 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1652
      • 1301 on SlideShare
      • 351 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 38
    Most viewed embeds
    • 274 views on http://htmlcenter.com
    • 74 views on http://www.htmlcenter.com
    • 3 views on http://www.surianee.com

    more

    All embeds
    • 274 views on http://htmlcenter.com
    • 74 views on http://www.htmlcenter.com
    • 3 views on http://www.surianee.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories