LearnerId:

Php Programming


Content List

Skip Navigation Links.
Collapse Total Week Wise ContentTotal Week Wise Content
Collapse Week1Week1
Collapse Week2Week2
Collapse Week3Week3
Collapse Week4Week4
Collapse Week5 : DataBaseWeek5 : DataBase
Collapse Week6:Week6:
Collapse Week 7: ProjectWeek 7: Project

PHP STRING :-

String Charecter, Number, Special Charecter और arithmetic values का sequence होता है । String को single quotation marks ( ' ' ) या double quotation marks ( " " ) के अंदर define करते है

$string1 = 'Hello PHP';

$string2 = "Hello World";

String में कुछ Predefine string function होते है । जिनका use करके string को menuplate कर सकते है । जैसे calculating the length of the string, find substring or characters, replace part of string with different characters etc.

1. Calculate The Length of a String [ strlen( ) ] :- strlen( ) function का use string की length ज्ञात करने के लिए किया जाता है अर्थात यह function string की length को return करता है ।

Example


Figure:-1 php strlen( ) function

उपरोक्त program को किसी भी browser पर run करने पर तथा निम्न output show होता है।


Figure:-1 php strlen( ) output


2. Count the number of the words in a string [ str_word_count( ) ] :- str_word_count() function का use एक string में number of the words को Count करने के लिए किया जाता है अर्थात यह function दी गयी string के number of the word को count करके बताता है ।

Example


Figure:-1 php str_word_count( ) function

उपरोक्त program को किसी भी browser पर run करने पर तथा निम्न output show होता है।


Figure:-2 php str_word_count( ) output


3. Replace Text Within A String [str_replace()]:- str_replace() function का use एक string में कुछ charecters को अन्य charecters के साथ replace करने के लिए किया जाता है

Example


Figure:-1 php str_replace( ) function

उपरोक्त program को किसी भी browser पर run करने पर उपरोक्त statement "welcome in India" में str_replace() function की help से India के स्थान पर Rajasthan show होता है अर्थात India को Rajasthan के द्वारा replace किया गया । Output निम्न है-


Figure:-2 php str_replace( ) output


4. Reverse a String [strrev()]:- strrev() function का use किसी भी String को reverse order में करने के लिए किया जाता है

Example


Figure:-1 php strrev() function

उपरोक्त program को किसी भी browser पर run करने पर उपरोक्त statement "welcome in India" , strrev() function की help से Reverse Order "!aidnI ni emocleW" में show होता है । Output निम्न है-


Figure:-2 php strrev() output


5. Searching Specific text within a String [strpos()]:- strpos() function का use किसी भी String में specific text को search करके उसकी position return करने के लिए किया जाता है ।
यदि string में कोई word match होता है तो function first match के charecters position को return करता है अन्यथा यह False return करता है ।

Example


Figure:-1 php strpos() function

उपरोक्त program को किसी भी browser पर run करने पर तथा निम्न output show होता है।


Figure:-2 php strpos() function output

left right