ASP
  Home arrow ASP arrow Page 3 - Mimicking PHP's String Formatting Function...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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? 
ASP

Mimicking PHP's String Formatting Functions
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2004-06-21

    Table of Contents:
  • Mimicking PHP's String Formatting Functions
  • str_word_count and ucfirst
  • strip_tags
  • str_pad

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Mimicking PHP's String Formatting Functions - strip_tags


    (Page 3 of 4 )

    PHP brings a great function to the table called 'strip_tags'. Through it we can pass a string, and out the other side pops out the stripped-down shadow of its former self. This would be extremely useful in a forum or chat area, where people are constantly trying to throw in some HTML formatting.

    There are a couple of ways we could approach this. One would be to flow through the entire string, look for any '<' brackets, and methodically pull away the information around the tags into chunks that can be pieced together separately.

    Needless to say, this is a very laborious approach to solving the issue. How much nicer would it be to just use Regular Expressions? A lot, so let's do it! If you need to know more about regular expressions, here's a great tutorial: http://www.devarticles.com/c/a/ASP/The-Complete-Regular-Expression-Guide. But for now we'll use a simple one, just looking for the common brackets that enclose a tag. Here's the function:

    '===================================================

    Function stripTags( strToStrip )

    '===================================================

    Dim objRegExp

    strToStrip = Trim( strToStrip & "" )

    If Len( strToStrip ) > 0 Then

    Set objRegExp = New RegExp

    objRegExp.IgnoreCase = True

    objRegExp.Global = True

    objRegExp.Pattern= "<[^>]+>"

    strToStrip = objRegExp.Replace(strToStrip, "")

    Set objRegExp = Nothing

    End If

    StripHTMLTags = strToStrip

    End Function

    So as you read through the lines of code, you should be able to figure it out. We build the regular expression to find any tags, and blow through the entire string replacing the tags with “”. How handy! Now let's move on to the last.

    More ASP Articles
    More By Justin Cook


     

    ASP ARTICLES

    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application
    - Easy Error Management





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway