strcspn() Function in PHP

strcspn() function இங்கு இரண்டு string argument ஆக அனுப்புகிறோம், முதல் string இன் character இரண்டாவது string இல் எங்காவது ஆரமித்தால் அந்த character வரை முதல் string இன் எண்ணிக்கை count செய்யபடுகிறது.

strcspn(main_string, second_string, start_position, string_length)

strcspn() function இங்கு நான்கு argument அனுபப்படுகிறது. அவைகள் முறையே main_string, second_string, start_position, string_length போன்றவை ஆகும். இங்கு string length கண்டறியபடுகிறது. இங்கு whitespaces-ம் length இல் சேர்த்துக்கொள்ளபடும். Note:

Example1

<?php
echo strcspn("peacock is my favourite bird", "b");    
?>

மேலே உள்ள Example1-ஐ கவனிக்கவும் strcspn என்ற function இல் "peacock is my favourite bird" முதல் argument மற்றும் "b" என்பது இரண்டாவது argument ஆக அனுபப்படுகிறது. இங்கு "b" என்ற character இரண்டாவது string இல் வந்துள்ளது. strcspn என்ற function முதல் string இல் "b" என்ற character க்கு முன்னால் உள்ள character களின் எண்ணிக்கையை count செய்கிறது. எனவே output 24 என கிடைக்கிறது.இங்கு whitespaces-ம் length இல் சேர்த்துக்கொள்ளபடும்.

Output:

34

Example2

<?php
echo strcspn("learn programming in tamil", "p");  
?>

மேலே உள்ள Example2-ஐ கவனிக்கவும் strcspn என்ற function இல் "learn programming in tamil" என்ற string முதல் argument மற்றும் "p" என்ற character இரண்டாவது argument ஆக அனுபப்படுகிறது. இங்கு "p" என்ற character முதல் string இல் வந்துள்ளது. strcspn என்ற function முதல் string இல் "p" என்ற character க்கு முன்னால் உள்ள character களின் எண்ணிக்கையை count செய்கிறது. எனவே output 6 என கிடைக்கிறது.இங்கு whitespaces-ம் length இல் சேர்த்துக்கொள்ளபடும்.

Output:

6

Comments