Programming Basics

  Home arrow Programming Basics arrow Page 31 - 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 - Parsing URLs


    (Page 31 of 37 )

    Earlier, we saw how to take an email address and parse it into its respective username and hostname parts. Fortunately, PHP provides built-in functionality for parsing URLs in the 'parse_url()' function. All we need to do is to pass it the URL, and it will break it down and return an associative array that we can easily work with. Let's look at some code that will demonstrate the different parts returned by this function.

    <?php
    $url 
    "http://www.invaliddomain.ivd/dir1/script.php?var1=23";
    $parts parse_url ($url);

    echo 
    "scheme: {$parts['scheme']}&lt;br /&gt;
    host: {$parts['host']}&lt;br /&gt;
    path: {$parts['path']}&lt;br /&gt;
    query string: {$parts['query']}&lt;br /&gt;"
    ;
    ?>

    This would output:

    scheme: http
    host: www.invaliddomain.ivd
    path: /dir1/script.php
    query string: var1=23

    As you can see, this broke the URL down into several different pieces. This function will also return the user, password, and port number if it is included in the URL. Not only will this function work for http, but ftp and other schemes as well. Keep in mind, however, that this function is not meant to validate a URL, but to simply break it down.

    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 9 - Follow our Sitemap