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('') में भी लिख सकते हैं । Show
चलिए एक example से समझते हैं की PHP में
स्ट्रिंग कैसे use कर सकते हैं । Example
OutputString is collection of characters This is string पैरामीटर: - 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
Example for strlen() String FunctionSource Code : "; $len = strlen($str); echo "Length of String is ".$len; ?> Output : Hello World! Length of String is 12 Example for strtolower() String Function"; $lower = strtolower($str); echo "LowerCase String : ".$lower; ?> Output : Hello World! LowerCase String : hello world! Example for strtoupper() String Function"; $upper = strtoupper($str); echo "UpperCase String : ".$upper; ?> Output : Hello World! UpperCase String : HELLO WORLD! Example for str_replace() String Function"; $replace = str_replace("World", "Friends", $str); echo "Replaced String : ".$replace; ?> Output : Hello World! Replaced String : Hello Friends! Example for strcmp() String Function"; $compare2 = strcmp("Hello World", "hello World"); echo $compare2 . " Output : 0 -1 1 Example for trim() String Function"; $tr = trim($str, "Held!"); echo $tr; ?> Output : Hello World! o Wor Example for ltrim() String Function"; $ltr = ltrim($str, "Held!"); echo $ltr; ?> Output : Hello World! o World! Example for rtrim() String Function"; $rtr = rtrim($str, "Held!"); echo $rtr; ?> Output : Hello World! Hello Wor Example for ucwords() String Function"; $ucw = ucwords($str); echo $ucw; ?> Output : hello world! Hello World! Example for lcfirst() String Function"; $lcf = lcfirst($str); echo $lcf; ?> Output : Hello World! hello World! Example for ucfirst() String Function"; $ucf = ucfirst($str); echo $ucf; ?> Output : hello world! Hello world! Example for strrev() String Function"; $rev = strrev($str); echo "Reverse String : ".$rev; ?> Output : hello world! Reverse String : !dlrow olleh Example for strip_tags() String FunctionHello World!"; echo $str . " Output : Hello World! Hello World! Example for chop() String Function"; $ch = chop($str, "world!"); echo $ch; ?> Output : Hello World! Hello W Example for htmlentities() String FunctionHello World!"; echo $str . " Output : 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.. |