PHP
  Home arrow PHP arrow Page 5 - String Theory
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

String Theory
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2001-09-20

    Table of Contents:
  • String Theory
  • Secret Agent Man
  • Running Backwards
  • Getting Into Position
  • Instant Paralysis
  • A Quick Trim
  • Working The Web

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    String Theory - Instant Paralysis


    (Page 5 of 7 )

    You can also search for specific patterns in your strings with regular expressions, via PHP's preg_match() function.

    <? $str = "johndoe@somedomain.com"; $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/"; // returns true echo preg_match($pattern, $str); ?>
    You can also use the ereg() function to perform a regular expression match,

    <? $str = "yo ho ho and a bottle of gum"; // returns true echo ereg("bo*", $str); ?>
    and the ereg_replace() function to perform a search-and-replace operation.

    <? $str = "yo ho ho and a bottle of gum"; // returns "yo ho ho and a bottle of rum" echo ereg_replace("gum", "rum", $str); ?>
    If you need to perform substitution within a string, PHP also has the str_replace() function, designed specifically to perform find-and-replace operations.

    <? $str = "...as Michael dropped into a crouch and came up under Frank's punch, he swiveled to the side and kicked Frank in the spine, immediately breaking one of Frank's vertebrae and rendering him paralyzed for life..."; // returns "...as Michael dropped into a crouch and came up under John's punch, he swiveled to the side and kicked John in the spine, immediately breaking one of John's vertebrae and rendering him paralyzed for life..." echo str_replace("Frank", "John", $str); ?>

    More PHP Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    PHP ARTICLES

    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter
    - Building Your Own System Tray Application Us...
    - Structuring Your Projects for Web Applicatio...
    - Inserting, Updating and Deleting Database Ro...
    - Building Your Own Desktop Notepad Applicatio...
    - Web Application Security Overview
    - Working with the Active Record Class in Code...
    - Generate PDF Documents with PHP on the Windo...
    - Sending Email with PHP Networking
    - Performing Strict Validation with the Code I...
    - The preg_replace_callback() function in PHP
    - PHP Networking
    - Validating Web Forms with the Code Igniter P...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT