-
[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.
-
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
Forum Rules
|
|
Bookmarks