🟡 Control Flow · Lesson 11
String Functions
String Functions
PHP String Functions
PHP has many built-in functions to work with text.
Common Functions
<?php
$s = "CodeKaFunda";
echo strlen($s); // 11
echo strtoupper($s); // CODEKAFUNDA
echo substr($s, 0, 4); // Code
echo str_replace("Funda", "Master", $s); // CodeKaMaster
?>
explode and implode
<?php
$csv = "apple,mango,kiwi";
$arr = explode(",", $csv); // array
echo $arr[1]; // mango
echo implode(" - ", $arr); // apple - mango - kiwi
?>
Summary
- strlen, strtoupper, substr, str_replace work on text.
explodesplits a string into an array;implodejoins back.
PHP String Functions
PHP में text के साथ काम करने के लिए कई built-in functions हैं।
Common Functions
<?php
$s = "CodeKaFunda";
echo strlen($s); // 11
echo strtoupper($s); // CODEKAFUNDA
echo substr($s, 0, 4); // Code
echo str_replace("Funda", "Master", $s); // CodeKaMaster
?>
explode और implode
<?php
$csv = "apple,mango,kiwi";
$arr = explode(",", $csv); // array
echo $arr[1]; // mango
echo implode(" - ", $arr); // apple - mango - kiwi
?>
सारांश
- strlen, strtoupper, substr, str_replace text पर काम करते हैं।
explodestring को array में तोड़ता है;implodeवापस जोड़ता है।