Programming Basics

  Home arrow Programming Basics arrow Page 32 - 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 - Encoding for URLs


    (Page 32 of 37 )

    When we are going to pass data through a URL, we must encode it some way, as the HTTP standards dictate that only certain characters are allowed to exist in a URL. The 'url_encode()' function provides this functionality for us. It will convert the majority of non-alphanumeric characters into a percent sign followed by the two digit hex code for that character. Spaces will be converted to a plus sign.

    It is important to encode data being passed through the URL so that browsers will not mangle it. Without encoding, the integrity of any data passed can not be trusted. Encoding data with the 'url_encode()' function is as simple as passing it the data we want encoded. Let's see an example.

    <?php
    $mystring 
    'Here is some data!';
    $encoded urlencode ($mystring);
    ?>

    Now, that would produce the following output:

    Here+is+some+data%21

    In order to decode the data, we would pass it to the 'url_decode()' function. It is good to note, however, that data passed to a PHP script from the URL does not need to be decoded. PHP handles this automatically for us.

    More Programming Basics Articles
    More By Matt Wade

    blog comments powered by Disqus

    PROGRAMMING BASICS ARTICLES

    - The Transliteration Operator in Perl
    - Perl String Processing Functions
    - Perl String Processing
    - Control Flow Constructs: Loops Conclusion
    - Loop Control Constructs
    - Control Flow Constructs: the For and Foreach...
    - Loops and Control Flow Constructs
    - Expression Modifiers for Perl Control Flow C...
    - Logical Operators and Control Flow Constructs
    - Comparing Strings with Control Flow Construc...
    - Perl Operators and Control Flow Constructs
    - Control Flow Constructs
    - More Time Manipulation with PHP
    - Validating and Manipulating Dates with PHP
    - Using the Date Constructor in PHP

    Developer Shed Affiliates

     



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