Search
 
SCRIPT & CODE EXAMPLE
 

PHP

PHP substr_count — Count the number of substring occurrences

<?php
$text = 'This is a test';
echo strlen($text); // 14

echo substr_count($text, 'is'); // 2

// the string is reduced to 's is a test', so it prints 1
echo substr_count($text, 'is', 3);

// the text is reduced to 's i', so it prints 0
echo substr_count($text, 'is', 3, 3);

// generates a warning because 5+10 > 14
echo substr_count($text, 'is', 5, 10);


// prints only 1, because it doesn't count overlapped substrings
$text2 = 'gcdgcdgcd';
echo substr_count($text2, 'gcdgcd');
?>
Comment

PREVIOUS NEXT
Code Example
Php :: mkdir permission denied php 
Php :: date format change in laravel 
Php :: iteration in php 
Php :: get count laravel 
Php :: php export excel 
Php :: model json laravel accessor to convert to array 
Php :: item count in cart quantitiy woocommerce 
Php :: laravel group route controller 
Php :: laravel sail publish 
Php :: wordpress get current taxonomy 
Php :: php check if headers already sent 
Php :: wp redirect 
Php :: woocommerce profile photo upload 
Php :: php info 
Php :: laravel update table column 
Php :: get month first date and last date in php 
Php :: replace multiple characters one string php 
Php :: Undefined index: id 
Php :: ubuntu laravel storage permission 
Php :: yii2 set cookie 
Php :: how remove empty value in array php 
Php :: remove all sessions in laravel 
Php :: Sending Data over another website via PHP 
Php :: where is the php ini file located on server 
Php :: php remove and  
Php :: multiple search filter in laravel 
Php :: php 
Php :: laravel password encryption 
Php :: range in php 
Php :: phpmyadmin reset auto_increment 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =