www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Finding number of a particular character in a string

  1. #1
    Join Date
    Oct 2006
    Posts
    10

    resolved [RESOLVED] Finding number of a particular character in a string

    I've been trying to find a solution for this, but my search has been unsuccessful.

    I'd like to find a PHP function which counts the number of forward slashes ("/") in a string.

    Example 1: The string "var/public_html/website/index.php" should return 3.

    Example 2: The string "directory/subdirectory" should return 1.


    It seems easy, but I haven't been able to find anything that does this.

  2. #2
    Join Date
    Oct 2006
    Posts
    10
    Oops, just answered my own question. Hope this helps someone who might be having a similar problem.


    $mypath = ""var/public_html/website/index.php";

    $number_of_slashes = substr_count($mypath, "/");

    echo "Number of slashes: " . $number_of_slashes;

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