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
?>PHPstr_word_count():
str_word_count() function String में शब्दों (words) की संख्या return करता है।
<?php
$text = "PHP is awesome!";
echo str_word_count($text);
// Output: 3
?>PHPstrrev():
strrev() function String को उल्टा (reverse) कर देता है।
<?php
$text = "VIKAS";
echo strrev($text);
// Output: SAKIV
?>PHPstrpos():
strpos() String में substring का पहला occurrence खोजता है और उसकी position return करता है।
<?php
$text = "I love PHP!";
echo strpos($text, "PHP");
// Output: 7
?>PHPstr_replace():
str_replace() String में किसी substring को replace करता है।
<?php
$text = "I love Java!";
$newText = str_replace("Java", "PHP", $text);
echo $newText;
// Output: I love PHP!
?>PHPstrtolower():
strtolower() String को lowercase में बदलता है।
<?php
$text = "HELLO WORLD!";
echo strtolower($text);
// Output: hello world!
?>PHPstrtoupper():
strtoupper() String को uppercase में बदलता है।
<?php
$text = "hello world!";
echo strtoupper($text);
// Output: HELLO WORLD!
?>PHPucfirst():
ucfirst() String के पहले character को uppercase में बदलता है।
$text = "hello world!";
echo ucfirst($text); // Output: Hello world!<?php
$text = "hello world!";
echo ucfirst($text);
// Output: Hello world!
?>PHPlcfirst():
lcfirst() String के पहले character को lowercase में बदलता है।
<?php
$text = "HELLO WORLD!";
echo lcfirst($text);
// Output: hELLO WORLD!
?>PHPucwords():
ucwords() String में प्रत्येक शब्द के पहले character को uppercase में बदलता है।
<?php
$text = "hello world!";
echo ucwords($text);
// Output: Hello World!
?>PHPtrim():
trim() String के शुरू और अंत से whitespace को हटाता है।
<?php
$text = " Hello World! ";
echo trim($text);
// Output: Hello World!
?>PHPltrim():
ltrim() String के शुरूआत से whitespace को हटाता है।
<?php
$text = " Hello World! ";
echo ltrim($text);
// Output: Hello World!
?>PHPrtrim():
rtrim() String के अंत से whitespace को हटाता है।
<?php
$text = " Hello World! ";
echo rtrim($text);
// Output: " Hello World!"
?>PHPsubstr():
substr() String के एक हिस्से (substring) को return करता है।
<?php
$text = "Hello World!";
echo substr($text, 0, 5);
// Output: Hello
?>PHPstr_repeat():
str_repeat() String को repeat करता है।
<?php
$text = "PHP ";
echo str_repeat($text, 3);
// Output: PHP PHP PHP
?>PHPstr_shuffle():
str_shuffle() String के characters को random रूप से shuffle करता है।
<?php
$text = "PHP";
echo str_shuffle($text);
// Output: PPH (random)
?>PHPstr_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
) */
?>PHPexplode():
explode() String को delimiter के अनुसार array में बदलता है।
<?php
$text = "Apple,Banana,Mango";
$array = explode(",", $text);
print_r($array);
/* Output:
Array (
[0] => Apple
[1] => Banana
[2] => Mango
) */
?>PHPimplode():
implode() function Array को string में बदलता है।
<?php
$array = ["Apple", "Banana", "Mango"];
$text = implode(", ", $array);
echo $text;
// Output: Apple, Banana, Mango
?>PHPstrcmp():
strcmp() दो strings की तुलना करता है।
<?php
$text1 = "Hello";
$text2 = "hello";
echo strcmp($text1, $text2);
// Output: Non-zero (case-sensitive comparison)
?>PHPConclusion:
PHP में String Functions का उपयोग टेक्स्ट डेटा को analyze, manipulate और format करने के लिए किया जाता है।
str_replace()औरexplode()जैसे functions text को edit और organize करने में मदद करते हैं।strlen()औरstrpos()जैसे functions डेटा को analyze करते हैं।ucfirst()औरstrtoupper()जैसे functions टेक्स्ट को format करते हैं।

Welcome to HindiTutorials, your go-to platform for learning and mastering concepts in Hindi! Our mission is to make education accessible and simple for everyone by providing high-quality tutorials on programming, technology, and various other topics.