🟡 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.
  • explode splits a string into an array; implode joins 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 पर काम करते हैं।
  • explode string को array में तोड़ता है; implode वापस जोड़ता है।
← Back to PHP Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।