Results 1 to 2 of 2

Thread: exclude characters from counting?

  1. #1
    Join Date
    Mar 2008

    exclude characters from counting?

    Hello, I wanted to ask if you have a string like:
    is there a way to count the length of the string, excluding non-word characters (+,- or .)?

    thank you

  2. #2
    Join Date
    Aug 2004
    First thing that comes to mind (untested):
    PHP Code:
    $count strlen(preg_replace('/\W/'''$string); 
    "\W" is "any non-word character," so it would count a-ZA-Z0-9 and underscores. If you wanted it more restrictive, you would need a more specific regexp, such as '/[^a-ZA-Z]/' to replace anything that is not a letter.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles