SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    counting the occurances of a character in a string

    i need to find out how many directories deep a path is, by counting the slashes in it. i don't really know what function i should use though. i came up w/ this quickly:

    PHP Code:
    $count preg_match_all('#/#'$path$the_dumb_array_var_i_dont_need); 
    is that the best way? is there some other string function i should use that would be more effecient or "better?"

    thanks.
    Last edited by DR_LaRRY_PEpPeR; Jul 21, 2001 at 13:11.

  2. #2
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you qslack! that was fast! now how did i miss that function when i was looking through the manual last night?

    i just benched the 2 and substr_count() is 4 times faster than preg_match_all().

    great, thanks again!


Bookmarks

Posting Permissions

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