PHP String Functions Best Tutorial In Hindi 2025

PHP String Functions का उपयोग strings को manipulate (संपादित), format और analyze करने के लिए किया जाता है। ये functions टेक्स्ट के साथ काम करना आसान बनाते हैं।

PHP String Functions With Example:

यहां कुछ महत्वपूर्ण स्ट्रिंग फंक्शन्स हैं:

strlen():

strlen() function String की लंबाई (length) को return करता है।

<?php
  $text = "Hello World!";
  echo strlen($text); 
  
  // Output: 12
?>
PHP

str_word_count():

str_word_count() function String में शब्दों (words) की संख्या return करता है।

<?php
  $text = "PHP is awesome!";
  echo str_word_count($text); 
  
  // Output: 3
?>
PHP

strrev():

strrev() function String को उल्टा (reverse) कर देता है।

<?php
  $text = "VIKAS";
  echo strrev($text); 
  
  // Output: SAKIV
?>
PHP

strpos():

strpos() String में substring का पहला occurrence खोजता है और उसकी position return करता है।

<?php
  $text = "I love PHP!";
  echo strpos($text, "PHP"); 
  
  // Output: 7
?>
PHP

str_replace():

str_replace() String में किसी substring को replace करता है।

<?php
  $text = "I love Java!";
  $newText = str_replace("Java", "PHP", $text);
  echo $newText; 
  
  // Output: I love PHP!
?>
PHP

strtolower():

strtolower() String को lowercase में बदलता है।

<?php
  $text = "HELLO WORLD!";
  echo strtolower($text); 
  
  // Output: hello world!
?>
PHP

strtoupper():

strtoupper() String को uppercase में बदलता है।

<?php
  $text = "hello world!";
  echo strtoupper($text); 
  
  // Output: HELLO WORLD!
?>
PHP

ucfirst():

ucfirst() String के पहले character को uppercase में बदलता है।

$text = "hello world!";
echo ucfirst($text); // Output: Hello world!
<?php
  $text = "hello world!";
  echo ucfirst($text); 
  
  // Output: Hello world!
?>
PHP

lcfirst():

lcfirst() String के पहले character को lowercase में बदलता है।

<?php

  $text = "HELLO WORLD!";
  echo lcfirst($text); 
  
  // Output: hELLO WORLD!
?>
PHP

ucwords():

ucwords() String में प्रत्येक शब्द के पहले character को uppercase में बदलता है।

<?php
  $text = "hello world!";
  echo ucwords($text); 
  
  // Output: Hello World!
?>
PHP

trim():

trim() String के शुरू और अंत से whitespace को हटाता है।

<?php
  
  $text = "  Hello World!  ";
  echo trim($text); 
  
  // Output: Hello World!
?>
PHP

ltrim():

ltrim() String के शुरूआत से whitespace को हटाता है।

<?php
  $text = "  Hello World!  ";
  echo ltrim($text); 
  
  // Output: Hello World! 
?>
PHP

rtrim():

rtrim() String के अंत से whitespace को हटाता है।

<?php
  $text = "  Hello World!  ";
  echo rtrim($text); 
  
  // Output: "  Hello World!"
?>
PHP

substr():

substr() String के एक हिस्से (substring) को return करता है।

<?php
  $text = "Hello World!";
  echo substr($text, 0, 5); 
  
  // Output: Hello
?>
PHP

str_repeat():

str_repeat() String को repeat करता है।

<?php
  $text = "PHP ";
  echo str_repeat($text, 3); 
  
  // Output: PHP PHP PHP 
?>
PHP

str_shuffle():

str_shuffle() String के characters को random रूप से shuffle करता है।

<?php
  $text = "PHP";
  echo str_shuffle($text); 
  
  // Output: PPH (random)
?>
PHP

str_split():

str_split() String को characters के array में तोड़ता है।

<?php
  $text = "Hello";
  print_r(str_split($text)); 
  
  /* Output: 
  Array (
    [0] => H 
    [1] => e 
    [2] => l 
    [3] => l 
    [4] => o
    ) */
?>
PHP

explode():

explode() String को delimiter के अनुसार array में बदलता है।

<?php
  $text = "Apple,Banana,Mango";
  $array = explode(",", $text);
  print_r($array); 
  
  /* Output: 
  Array (
    [0] => Apple 
    [1] => Banana 
    [2] => Mango
    ) */
?>
PHP

implode():

implode() function Array को string में बदलता है।

<?php
  $array = ["Apple", "Banana", "Mango"];
  $text = implode(", ", $array);
  echo $text; 
  
  // Output: Apple, Banana, Mango

?>
PHP

strcmp():

strcmp() दो strings की तुलना करता है।

<?php
  $text1 = "Hello";
  $text2 = "hello";
  echo strcmp($text1, $text2); 
  
  // Output: Non-zero (case-sensitive comparison)
?>
PHP

Conclusion:

PHP में String Functions का उपयोग टेक्स्ट डेटा को analyze, manipulate और format करने के लिए किया जाता है।

  • str_replace() और explode() जैसे functions text को edit और organize करने में मदद करते हैं।
  • strlen() और strpos() जैसे functions डेटा को analyze करते हैं।
  • ucfirst() और strtoupper() जैसे functions टेक्स्ट को format करते हैं।

error: Content is protected!! You are not allowed to copy.