Return the part of a string
substr() function string இன் குறிப்பிட்ட பகுதியை return செய்வதற்கு பயன்படுகிறது. இங்கு length ஆனது argument ஆக அனுபப்படுகிறது.
substr() Function in PHP
substr() function string இன் குறிப்பிட்ட பகுதியை return செய்வதற்கு பயன்படுகிறது. இங்கு length ஆனது argument ஆக அனுபப்படுகிறது.
substr(string, start, length)
Example1
<?php
$input = "Opportunities don't happen, you create them";
echo substr($input, "14");
?>
மேலே உள்ள Example1-ஐ கவனிக்கவும் $input என்ற variable-இல் "Opportunities don't happen, you create them" என்ற string argument-ஆக அனுப்பப்பட்டுள்ளது. இங்கு இரண்டாவது argument ஆக starting length "14" என கொடுகப்பட்டுள்ளது, எனவே don't happen, you create them என்ற position இல் இருந்து ஆரம்பமாகிறது. output ஐ கவனிக்கவும்.
don't happen, you create them
Example2
<?php
$data = "Great minds discuss ideas";
echo substr($data,10,20);
?>
மேலே உள்ள Example2-ஐ கவனிக்கவும் $data என்ற variable-இல் "Great minds discuss ideas" என்ற string argument-ஆக அனுப்பப்பட்டுள்ளது. இங்கு இரண்டாவது மற்றும் மூன்றாவது argument ஆக starting,ending length கொடுகப்பட்டுள்ளது, எனவே அதனை பொருத்து "s discuss ideas" என்ற string ஆனது output ஆக கிடைக்கிறது.
s discuss ideas