🟡 Control Flow  ·  Lesson 11

String Functions

PHP String Functions

PHP has many built-in functions to work with text.

Common Functions

<?php
  $s = "CodingEasily";
  echo strlen($s);            // 11
  echo strtoupper($s);        // CODINGEASILY
  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 = "CodingEasily";
  echo strlen($s);            // 11
  echo strtoupper($s);        // CODINGEASILY
  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.

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

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.