Beginner Friendly · Hands-on · Free

counts the number of times a substring occurs in the given string

substr_count() function நாம் கொடுக்கும் string இல் substring எண்ணிக்கையை கண்டறிய பயன்படுகிறது. இது ஒரு case-sensitive function ஆகும்.

5 min read Updated Dec 02, 2025

substr_count() Function in PHP

substr_count() function நாம் கொடுக்கும் string இல் substring எண்ணிக்கையை கண்டறிய பயன்படுகிறது. இது ஒரு case-sensitive function ஆகும்.

substr_count(string, substring, start, length)

Note: substr_count() function நான்கு argument கள் அனுபப்படுகிறது. அவைகள் முறையே string,substring,start மற்றும் length. முதல் argument sring மற்றும் இரண்டாவதாக substring argument ஆக அனுபப்படுகிறது. இங்கு string இல் உள்ள substring களின் எண்ணிக்கையை கண்டறிய பயன்படுகிறது, case-sensitive ஆகவும் செயல்படுகிறது. அதேபோல் start மற்றும் length கொடுக்கும் போது அதனை பொருத்து substring களின் count calculate செய்யபடுகிறது.

Example1

<?php
$data = "I will be in the room in 1 hour";
echo substr_count($data,"in");  
?>

மேலே உள்ள Example1-ஐ கவனிக்கவும் $data என்ற variable-இல் "I will be in the room in 1 hour" என்ற string argument-ஆக அனுப்பப்பட்டுள்ளது. substr_count() function $data variable இல் உள்ள string மற்றும் count value கண்டறிய வேண்டிய அதாவது ("in") substring இரண்டாவது argument ஆக உள்ளது. இங்கு ("in") substring இரண்டு முறை வந்துள்ளது எனவே count value 2 என கிடைக்கிறது.

Output:

2

Example2

<?php
$input = "I will go To New York To meet my friend";
echo substr_count($input,"to");  
?>

மேலே உள்ள Example2-ஐ கவனிக்கவும் $input என்ற variable-இல் "I will go To New York To meet my friend" என்ற string argument-ஆக அனுப்பப்பட்டுள்ளது. substr_count() function $input variable இல் உள்ள string மற்றும் count value கண்டறிய வேண்டிய அதாவது ("to") substring இரண்டாவது argument ஆக உள்ளது. இங்கு input string To என்ற string இரண்டு முறை uppercase ஆக வந்துள்ளது substring lowercase ஆக உள்ளது substr_count() function case-sensitive function எனவே output 0 என கிடைக்கிறது.

Output:

0

இது பற்றிய தங்களின் கருத்துகளை இங்கே பதிவிடுங்கள் . இது பயனுள்ளதாக விரும்பினால் மற்றவர்களுக்கும் இதை share செய்யுங்கள்.