Programming Basics

  Home arrow Programming Basics arrow Page 23 - 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 - Substrings (and searching)


    (Page 23 of 37 )

    Many varied tasks can be accomplished by using substrings. We will define a substring as a string that makes up any portion of another string. This could be as small as a single character, or as large as the entire length of the string. In this section, we will examine different methods for finding substrings, replacing those substrings, and other related duties. First, let's take a look at the functions covered in this section.

  • substr(string, start [, length]) -Using this function, we can extract parts of a string to store in another string, or utilize in other functions.
  • substr_count(haystack, needle) -This function allows us to count the number of times a substring occurs within a string.
  • str_replace(haystack, replacement, needle) -With this function, we can replace all occurrences of a substring within a string with a different string.
  • substr_replace(string, replacement, start [, length]) -This is a different method of replacing portions of a string based on positions rather than searching for a substring.
  • strstr(haystack, needle) -Also called 'strchr', this function will find the first occurrence of a substring and return the portion of the string from that occurrence on.
  • stristr(haystack, needle) -This provides the same functionality as 'strstr', but searches in a case-insensitive manner.
  • strrchr(haystack, needle) -This function is identical to strstr', except that it finds the last occurrence of a substring instead of the first.
  • strpos(haystack, needle) -This function is similar to the 'strstr' function, with the difference being that an integer specifying where the first occurrence begins is returned rather than a string.
  • strrpos(haystack, needle) -An integer specifying where the last occurrence of a character is found within a string is returned by this function.
  • strspn(string1, string2) -This function will return the number of sequential characters at the beginning of a string that match the characters supplied in the second parameter.
  • strcspn(string1, string2) -Rather than providing the number of characters that match the second parameter, this function returns the number of sequential characters that do not match.

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