Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to count no of words in a string in php without using string functions

echo "".count(explode(" ","Sushant Shivam Sumit"));
Comment

how to count no of words in a string in php without using string functions

<?php
$str = "Shivam Sumit Sushu";
$c = 0;
$i = 0;
for ($i=0; $i < strlen($str); $i++) { 
    // echo "".$str[$i]."<br>";
    if ($str[$i]==" ") {
        $c += 1;
    }
}
if ($str[$i - 1] != " ") {
    $c += 1;
}
echo "Words in '$str' are $c";
?>
Comment

count words in string php

#Text must be in double-qoutes in brackets

echo str_word_count("Text goes here...");
Comment

PREVIOUS NEXT
Code Example
Php :: wordpress get link to post by id 
Php :: how to reverse fetch assoc in php 
Php :: Using middleware auth laravel in controller constructor 
Php :: run python script from batch file with arguments 
Php :: increase upload limit in phpmyadmin docker 
Php :: diff for seconds laravel carbon 
Php :: php display errors 
Php :: laravel table in model 
Php :: php parse url get path 
Php :: php artisan down 
Php :: composer 
Php :: php array_map passing parameters 
Php :: toaster message in laravel 
Php :: phpunit repeat 
Php :: php subtract date from today 
Php :: php bubble sort 
Php :: Auth::routes(); why display error in route laravel 8 
Php :: carbon random future date 
Php :: laravel date default now 
Php :: fill zero on php 
Php :: is users logged in laravel blade 
Php :: how to compare two versions in php 
Php :: php hash password 
Php :: woocommerce get all subscriptions by user id 
Php :: php sqrt 
Php :: how to check if there is an authenticated user laravel 
Php :: how to display the responce of curl in php 
Php :: php change string to url friendly 
Php :: carbon parse timestamp 
Php :: if browser url is having query string after domain name in it check using php 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =