www.webdeveloper.com
Results 1 to 2 of 2

Thread: exclude characters from counting?

  1. #1
    Join Date
    Mar 2008
    Posts
    32

    exclude characters from counting?

    Hello, I wanted to ask if you have a string like:
    Code:
    $my_s='ASRGREGTGTR----REGREGRE+++RRRRRR....';
    is there a way to count the length of the string, excluding non-word characters (+,- or .)?

    thank you

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,330
    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.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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