Programming Basics

  Home arrow Programming Basics arrow Page 8 - PHP Strings Primer
PROGRAMMING BASICS

PHP Strings Primer
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2003-07-11

    Table of Contents:
  • PHP Strings Primer
  • The Basics
  • Single Quotes
  • Double Quotes
  • Heredoc
  • Concatenation
  • Displaying Strings
  • echo
  • print
  • printf
  • Strings Formatting
  • Preparing user input for comparisons
  • Capitalization
  • Reversing strings
  • Padding strings
  • Multiple Lines
  • Data Preparation
  • Adding and Removing Slashes
  • Dealing with HTML Tags and Entities
  • Counting
  • Checking password strength
  • Generating Statistics
  • Substrings (and searching)
  • Extracting Substrings
  • Counting Paragraphs
  • Filtering Words
  • Working with email addresses
  • Manually Stripping Tags
  • Password Strength Revisited
  • Handling URLs and Base64-encoding
  • Parsing URLs
  • Encoding for URLs
  • Encoding for Email
  • Hashing
  • Verifying Integrity
  • User Authentication
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    PHP Strings Primer - echo


    (Page 8 of 37 )

    The echo language construct is the most common method used for displaying strings as well as other data. It is very straight-forward and simple to use. The first thing we should notice is that echo is not a function at all. It is a language construct of PHP. What this means to us is that it is not always necessary to use parentheses with echo as it is with functions. for example, the following statement:

    <?php
    echo 'Hello';
    ?>

    Is just as valid as:

    <?php
    echo ('Hello');
    ?>

    In fact, the preferable, and in some cases mandatory, use of 'echo' is without parentheses. This can be demonstrated by an instance where the use of parentheses would be illegal. If you are passing multiple parameters to echo, then it must be done without parentheses, like so:

    <?php
    echo "First String\n""Second String";
    ?>

    The echo construct also provides a shorthand way for displaying content by using a short opening PHP tag immediately followed by an equal sign, then the string to display, and finally closed by a closing PHP tag. A common use for this method is for populating the action field of a HTML form element.

    <?php
    &lt;FORM method=POST action="&lt;?=$_SERVER['PHP_SELF']?&gt;"&gt;
    ?>

    It is worth noting that this shorthand technique may not work in all situations. If your server administrator has disabled the use of short opening tags for PHP, attempting to use this technique will result in fatal errors.

    More Programming Basics Articles
    More By Matt Wade

    blog comments powered by Disqus

    PROGRAMMING BASICS ARTICLES

    - Control Flow Constructs
    - More Time Manipulation with PHP
    - Validating and Manipulating Dates with PHP
    - Using the Date Constructor in PHP
    - Calendar Construction with PHP
    - PHP`s Calendar Package
    - Getting Modified Versions and Correct Dates ...
    - Combining Date Functions in PHP
    - Using PHP for Date and Time in Programming
    - More Exception Handling with PHP
    - Exception Handling in PHP
    - Error Logging and Handling Exceptions
    - Configuration Directives for Error and Excep...
    - Error and Exception Handling
    - Python Modules for Games


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap