Formatting string in php in hindi


इस PHP tutorial में हम PHP String के बारे में बात करेंगे । इस से पहले tutorial में हमने PHP data types में string डाटा टाइप के बारे में सीखा था । String characters का collection होता हैं PHP में String को double quots में लिखा जाता हैं । Double quots[""] में लिखने के साथ साथ string को single quots[''] में भी लिख सकते हैं ।

चलिए एक example से समझते हैं की PHP में स्ट्रिंग कैसे use कर सकते हैं ।
निचे दिए गए example में हम एक स्ट्रिंग को एक variable में store करते हैं । String को हम direct echo[] फंक्शन की मदत से display करा सकते हैं या variable के द्वारा भी हम display करा सकते हैं ।

Example



		
		

Output

  
String is collection of characters
This is string

पैरामीटर: -
$str - एक वेरिएबल
This is string - एक स्ट्रिंग
String is collection of characters- एक स्ट्रिंग
echo - echo[] एक PHP का readymade function हैं जिसके द्वारा हम value को display करा सकते हैं ।

PHP String functions:-

PHP में string के कुछ function भी है जो विभिन्न प्रकार के task को पूरा करने में प्रयोग किये जाते हैं । चलिए PHP string function के बारे में बात करते हैं ।

The Length of a String:-

PHP strlen[] function स्ट्रिंग की लंबाई का पता लगाने के लिए उपयोग किया जाता है। strlen[] फ़ंक्शन का निम्नलिखित उदाहरण है।

Example

Str_words_count[] function-

PHP str_word_count [] function का उपयोग पूर्ण स्ट्रिंग के शब्दों [words] की संख्या गिनती[count] करने में किया जाता हैं ।


Example

PHP strrev[]-

PHP strrev[] फ़ंक्शन का उपयोग पूर्ण स्ट्रिंग को उलटने [reverse] के लिए किया जाता है।


Example

PHP str_replace[] function -

PHP str_replace[] function कुछ characters को स्ट्रिंग में कुछ अन्य characters के साथ बदलने[replace] के लिए उपयोग किया जाता है।नीचे दिया गया उदाहरण "Learn" के साथ "Study" को replace सकते हैं ।:नीचे दिए गए उदाहरण में हम "Study के साथ "Learn" की जगह लेंगे:

Example

strpos[] function :-

PHP strpos[] फ़ंक्शन एक string के अंदर एक text word [स्ट्रिंग] की position खोज के लिए उपयोग किया जाता है। निचे के उदाहरण में, हम "How are you?" स्ट्रिंग में "you" की position खोज करेंगे।

Example

Strcmp[] fuction:-

PHP strcmp[] function का उपयोग दो स्ट्रिंग की तुलना[compare] के लिए किया जाता है।

String में multiple characters होते है | PHP में String के लिए 70+ string functions है जिनका इस्तेमाल string पर operation करने के लिए किया जाता है |

PHP में कुछ ज्यादा इस्तेमाल होनेवाले String Functions

String FunctionDescription
strlen[] String की length को return करता है |
strtolower[] Uppercase string को Lowercase string में convert कर देता है |
strtoupper[] Lowercase string को Uppercase string में convert कर देता है |
str_replace[] String में से कुछ characters या substring को किसी दुसरे character या substring से replace किया जाता है |
strcmp[] यहाँ पर दो strings को compare किया जाता है |
trim[] शुरुआत में और आखिरी के substring या characters को trim किया जाता है |
ltrim[] left-side मतलब शुरुआत के substring या characters को trim किया जाता है |
rtrim[] right-side मतलब आखिरी के substring या characters को trim किया जाता है |
ucwords[] words के हर पहले character को lowercase से uppercase में convert कर देता है |
lcfirst[] string में से पहला character uppercase से lowercase में convert कर देता है |
ucfirst[] string में से पहला character lowercase से uppercase में convert कर देता है |
strrev[] string को reverse किया जाता है |
strip_tags[] string में से html tags को rmove कर देता है |
chop[] String के आखिरी characters को remove कर देता है |
htmlentities[] string में से html code को html entites में convert कर देता है |

Example for strlen[] String Function

Source Code :

Output :

Hello World!
Length of String is 12

Example for strtolower[] String Function

Output :

Hello World!
LowerCase String : hello world!

Example for strtoupper[] String Function

Output :

Hello World!
UpperCase String : HELLO WORLD!

Example for str_replace[] String Function


Output :

Hello World!
Replaced String : Hello Friends!

Example for strcmp[] String Function

Output :

0
-1
1

Example for trim[] String Function

Output :

Hello World!
o Wor

Example for ltrim[] String Function

Output :

Hello World!
o World!

Example for rtrim[] String Function

Output :

Hello World!
Hello Wor

Example for ucwords[] String Function

Output :

hello world!
Hello World!

Example for lcfirst[] String Function

Output :

Hello World!
hello World!

Example for ucfirst[] String Function

Output :

hello world!
Hello world!

Example for strrev[] String Function

Output :

hello world!
Reverse String : !dlrow olleh

Example for strip_tags[] String Function

Output :

Hello World!


Hello World!

Example for chop[] String Function

Output :

Hello World!
Hello W

Example for htmlentities[] String Function

Output :

Hello World!


Hello World!


What are formatting strings in php?

Formatted strings use Format Specifiers to create the basic structure of the string. Format Specifiers are predefined character sequence that can be used to define the datatype to be stored or displayed as well a how any given value should be formatted i.e. precision, padding etc.

How to set string format in php?

PHP sprintf[] Function.
Replace the percent [%] sign by a variable passed as an argument: $number = 9; $str = "Beijing"; ... .
Using the format value %f: $number = 123; $txt = sprintf["%f",$number]; ... .
Use of placeholders: $number = 123; ... .
A demonstration of string specifiers: $str1 = "Hello";.

How to format text in php?

Formatting PHP text isn't done with PHP; it's done with HTML. You can do this in two ways. You can add HTML inside the PHP code or you can add the PHP code inside the HTML. Either way, the file must be saved as a .

How do you format a string for printing explain with suitable example in php?

The sprintf[] is an in-built function of PHP which writes a formatted string to a variable. It returns a formatted string. ... Parameter..

Chủ Đề