tag:blogger.com,1999:blog-19800266664857768432024-02-20T14:28:19.319-08:00Programming With PHPTCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.comBlogger48125tag:blogger.com,1999:blog-1980026666485776843.post-20261431315305229762009-04-27T00:00:00.000-07:002009-04-27T00:05:29.571-07:00Some PHP Exercises<p>Write a PHP program to set your locale information to that of theUnited Kingdom and display the currency of the UK. Once you are done, set the locale information to default. </p>TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-55864460923543836122009-04-26T23:45:00.000-07:002009-04-26T23:58:56.940-07:00The localeconvo() functionThis function returns an array that contains local numeric and currency formatting information.<br /><br />syntax: localconvo();<br /><br /><br />The array elements in the array returned by this function and their meanings are listed below:<br /><br />[decimal_point] - Decimal point character<br /><br />[thousands_sep] - Thousands separator<br /><br />[int_curr_symbol] - Currency symbol (example: USD)<br /><br />[currency_symbol] - Currency symbol (example: $)<br /><br />[mon_decimal_point] - Monetary decimal point character<br /><br />[mon_thousands_sep] - Monetary thousands separator<br /><br />[positive_sign] - Positive value character<br /><br />[negative_sign] - Negative value character<br /><br />[int_frac_digits] - International fractional digits<br /><br />[frac_digits] - Local fractional digits<br /><br />[p_cs_precedes] - True (1) if currency symbol is placed in front of a positive value, False (0) if it is placed behind<br /><br />[p_sep_by_space] - True (1) if there is a spaces between the currency symbol and a positive value, False (0) otherwise<br /><br />[n_cs_precedes] - True (1) if currency symbol is placed in front of a negative value, False (0) if it is placed behind<br /><br />[n_sep_by_space] - True (1) if there is a spaces between the currency symbol and a negative value, False (0) otherwise<br /><br />[p_sign_posn] - Formatting options:<br />0 - Parentheses surround the quantity and currency symbol<br />1 - The + sign is placed in front of the quantity and currency symbol<br />2 - The + sign is placed after the quantity and currency symbol<br />3 - The + sign is placed immediately in front of the currency symbol<br />4 - The + sign is placed immediately after the currency symbol<br /><br />[n_sign_posn] - Formatting options:<br />0 - Parentheses surround the quantity and currency symbol<br />1 - The - sign is placed in front of the quantity and currency symbol<br />2 - The - sign is placed after the quantity and currency symbol<br />3 - The - sign is placed immediately in front of the currency symbol<br />4 - The - sign is placed immediately after the currency symbol<br /><br />[grouping] - Array displaying how numbers are grouped (example: 3 indicates 1 000 000)<br /><br />[mon_grouping] - Array displaying how monetary numbers are grouped (example: 2 indicates 1<br />00 00 00)<br /><br />Example input:<br /><br />echo setlocale(LC_ALL,NULL);<br />print_r(localeconv());<br /><br />Example output:<br /><br />English_United States.1252Array ( [decimal_point] => . [thousands_sep] => , [int_curr_symbol] => USD [currency_symbol] => $ [mon_decimal_point] => . [mon_thousands_sep] => , [positive_sign] => [negative_sign] => - [int_frac_digits] => 2 [frac_digits] => 2 [p_cs_precedes] => 1 [p_sep_by_space] => 0 [n_cs_precedes] => 1 [n_sep_by_space] => 0 [p_sign_posn] => 3 [n_sign_posn] => 0 [grouping] => Array ( [0] => 3 ) [mon_grouping] => Array ( [0] => 3 ) )TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-5067581053642283072009-04-24T22:47:00.000-07:002009-04-24T22:49:35.956-07:00Some PHP ExercisesWhat is the use of the setlocale() function? <br /><br />Write a program to set your locale information to the UK and then revert back to your default locale information.TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-3920537871075047152009-04-24T22:33:00.000-07:002009-04-24T22:47:01.461-07:00The setlocale() functionThis function could be used to set locale information such as time, language, monetary and geographical information.<br /><br />syntax: setlocale(constant, location);<br /><br />constant – specifies what locale information should be set.<br />This parameter can contains the following values:<br />LC_ALL - All of the below <br />LC_COLLATE - Sort order <br />LC_CTYPE - Character classification and conversion (e.g. all characters should be lower or upper-case) <br />LC_MESSAGES - System message formatting <br />LC_MONETARY - Monetary/currency formatting <br />LC_NUMERIC - Numeric formatting <br />LC_TIME - Date and time formatting <br /> <br /><br />location – This parameter specifies which location the locale information should be set for.<br /><br />The location parameter can hold a string or an array. In case of a string, the country/region code needs to be specifued.<br /><br />If you are passing an array, the setlocale() function will scan through each of the array elements until it finds a valid region or country code and sets locale information for that region or country.<br /><br />In order to setyour default locale information , you could use<br /><br />setlocale(LC_ALL,NULL);<br /><br />Example input:<br /><br />echo setlocale(LC_ALL,"En-Us"); <br />In this example, we are setting the locale information to that of the US.<br /><br />Example output:<br /><br />English_United States.1252TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-49509802590552208342009-04-20T22:46:00.000-07:002009-04-20T23:01:17.399-07:00The levenshtein() functionThis function calculates the Levenshtein distance between two strings.<br /><br />syntax: levenshtein(string1,string2[,insert,replace,delete]);<br /><br />string1 and string2 are the two input strings.<br />insert- the cost of inserting a character<br />replace - the cost of replacing a character<br />delete - the cost of deleting a character<br /><br />By default, the cost for each operation is 1. However, we could also mention a cost, in which case, the Levenshtein cost would be calculated accordingly.<br /><br />Example input:<br /><br />$str1 = "John";<br />$str2 = "COrney";<br />echo levenshtein($str1,$str2);<br />echo "<br>";<br />echo levenshtein($str1,$str2,1,2,3);<br /><br /><br />Example output:<br /><br />5<br />8<br /><br /><strong>What is Levenshtein distance?</strong><br /><br />The Levenshtein distance between two strings is the minimum number of operations required to convert one string to another.<br /><br />The operations might include insert, replace or a delete.TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-91184230882220272312009-04-17T22:50:00.000-07:002009-04-17T22:53:59.462-07:00Some PHP Exercises<p> </p><ul><li>Write a program using the count_chars() function and determine the ASCII values of all English alphabets. </li></ul><p> </p><ul><li>How would you find the list of all characters that are not present in a string? </li></ul>TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-544143635032066432009-04-17T22:39:00.000-07:002009-04-17T22:43:55.985-07:00The count_chars() functionThis function can be used to determine the characters in a string and the number of times they are used.<br /><br />syntax: count_chars(string,mode);<br /><br />string – the input string<br />mode<br /><br />This parameter will determine the output of the count_chars() function.<br /><br />Following are the possible values and implications of this parameter.<br />0 – The function returns an array with the ASCII value of every possible character as the key and the number of occurrances in the string as the value.<br /><br />1 – The function returns anarray with the ASCII values as keys and the number of occurrances as values. In this case, the function creates an array element for characters that occur atleast once in the string.<br /><br />2 - The function returns anarray with the ASCII values as keys and the number of occurrances as values. The array elements will correspond to characters that are not present in the string.<br /><br />3 – The function will just display all the characters that are present in the input string.<br /><br />4 – The function displays all the characters that are not present in the input string.<br /><br /><br />Example input:<br /><br />$str = "Rooney";<br />echo $str;<br />echo "<br>";<br />print_r(count_chars($str,1));<br />echo "<br>";<br />echo count_chars($str,3);<br />echo "<br>";<br />echo count_chars($str,4);<br /><br />Example output:<br /><br />Rooney <br /> <br />Array ( [82] => 1 [101] => 1 [110] => 1 [111] => 2 [121] => 1 ) <br /> <br />Renoy <br />******TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-78671227375065067142009-01-07T19:08:00.000-08:002009-01-07T19:15:39.548-08:00UUEncoding and UUDecoding<div align="justify"><strong>convert_uuencode() function</strong></div><div align="justify"><br /><br />This function encodes a string using the Unix-to-Unix encoding algorith.</div><div align="justify"><br /><br />syntax: convert_uuencode(string);<br /><br /></div><div align="justify">string – the input string</div><div align="justify"><br /><strong>convert_uudecode() function</strong></div><div align="justify"><br />This function decodes a UU Encoded string.</div><div align="justify"><br /><br />snytax: convert_uudecode(string);<br /><br /></div><div align="justify">string – the encoded string</div><div align="justify"></div><div align="justify"><br />Example input:</div><div align="justify"></div><br /><div align="justify">$str = "This is Vince";<br />echo $str;<br />echo "";<br />echo convert_uuencode($str);<br />echo "";<br />echo convert_uudecode($encstr);</div><div align="justify"></div><div align="justify"><br />Example output:</div><div align="justify"></div><div align="justify">This is Vince -5&AI<?xml:namespace prefix = r!6 /><r!6:6yc90``> <div align="justify"></div><br /><div align="justify">Read <a href="http://email.about.com/od/emailbehindthescenes/a/uuencoding.htm" target="_blank">http://email.about.com/od/emailbehindthescenes/a/uuencoding.htm</a> for more on UU encoding</div></div>r!6:6yc90``><br /></r!6:6yc90``>TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-89048398617087540862008-10-26T21:51:00.000-07:002008-10-26T21:54:55.568-07:00The convert_cyr_string() function<div align="justify">This function converts a string in one Cyrillic character set to another.<br /><br />syntax: convert_cyr_string(string,from,to);<br /><br />from – the character set from which the string should be converted.<br />to – the character set to which the string should be converted.<br /><br />The from and two parameters can hold the following any of the following values.<br /><br />k - koi8-r<br />w - windows-1251<br />i - iso8859-5<br />a - x-cp866<br />d - x-cp866<br />m - x-mac-cyrillic </div><br /><br />Example input:<br /><br />$str = "This is Vince æøå";<br />echo $str;<br />echo "<br />";<br />echo convert_cyr_string($str,'w','a');<br /><br />Example output:<br /><br />This is Vince æøå<br />This is Vince ¦è¥TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-7609382846484688282008-10-17T22:35:00.000-07:002008-10-17T22:37:40.734-07:00The str_split() function<div align="justify">This function splits a string into an array of strings.<br /><br />syntax: str_split(string[,length]);<br /><br />string – the input string<br />length – the number of characters each element in the output array must hold. The default value is 1.</div><p>Example input:</p><p>$str1="This is a simple program number";<br />print_r(str_split($str1,5)); </p><p>Example output:</p><p>Array ( [0] => This [1] => is a [2] => simpl [3] => e pro [4] => gram [5] => numbe [6] => r )</p><p></p><p></p>TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-70071936044796259332008-10-16T01:31:00.000-07:002008-10-16T02:19:51.131-07:00The str_rot13() function<div align="justify">This function performs ROT13 encoding on a string.</div><div align="justify"><br />Syntax: str_rot13(string);</div><div align="justify"></div><div align="justify"><br />Example input: </div><div align="justify"><br /></div><div align="justify"></div><div align="justify">$str1="This is a simple program number 1";<br />$str2= str_rot13($str1);<br />echo $str2;<br />echo "<br />";<br />echo $str3= str_rot13($str2);</div><div align="justify"></div><div align="justify"><br />Example output: </div><div align="justify"><br /></div><div align="justify"></div><div align="justify">Guvf vf n fvzcyr cebtenz ahzore 1</div><div align="justify">This is a simple program number 1</div><div align="justify"></div><div align="justify"><strong><br />What is ROT13?<br /></strong></div><div align="justify"><br />A ROT13 enoding algorithm moves every character in a string 13 places forward. Numbers and special characters, however, are untouched.</div><br /><div align="justify"><br />Another interesting fact about the ROT13 algorithm is that the same algorithm could be used for encoding as well as decoding as you’d understand when you analyze the example.</div><br /><a href='http://www.mylot.com/BeautifulLife/8378'>myLot User Profile</a>TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-76518024575647205312008-10-10T23:05:00.000-07:002008-10-10T23:12:34.998-07:00The str_pad() function<div align="justify">This string could be used to pad a string to a new length.</div><div align="justify"><br />Syntax: str_pad(string,length[,pad-string,pad-type]);</div><div align="justify"><br />string – the input string</div><div align="justify"><br />length – the length of the padded string. If this value is lesser than length of the actual string, no effect will take place</div><div align="justify"><br />pad-string – the string to be used for padding. If this value is not specified, white spaces will be added as padding.</div><div align="justify"><br />pad-type –<br />This parameter can have the following values:</div><div align="justify"><br />STR_PAD_RIGHT: This is the default value and adds padding to the right of the string.<br />STR_PAD_LEFT: This value adds padding to the left end of the string.<br />STR_PAD_BOTH : This value adds padding to both the ends. If the number of characters to be added is not even, the right side is added an extra character.</div><div align="justify"></div><div align="justify"></div><div align="justify"></div><div align="justify"><br />Example input:<br /></div><br /><div align="justify"></div><div align="justify"></div><div align="justify"></div><div align="justify">$str1="This is a simple program";<br />echo str_pad($str1,40,"*",STR_PAD_BOTH);</div><div align="justify"></div><div align="justify"></div><div align="justify"></div><div align="justify"></div><div align="justify"><br />Example output:<br /></div><br /><div align="justify"></div><div align="justify"></div><div align="justify"></div><div align="justify">********This is a simple program********</div><div align="justify"></div>TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-58838671727231527652008-10-01T21:58:00.000-07:002008-10-01T22:00:40.900-07:00The str_shuffle() functionThis function randomly shuffles the characters in the string.<br /><br />Syntax: str_shuffle(string);<br /><br />string – the input string<br /><br />Example input:<br /><br />echo str_shuffle("Hello");<br />echo "<br />";<br />echo str_shuffle("Hello");<br /><br />Example output:<br /><br />lHole<br />oHellTCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-88997332606042406762008-10-01T21:56:00.000-07:002008-10-01T21:58:12.407-07:00The ord() functionThe ord() function returns the ASCII value of the first character of the string.<br /><br />Syntax: ord(string);<br /><br />string – the input string<br /><br />Example input:<br /><br />echo ord("Hello");<br /><br />Example output:<br /><br />72TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-39417041682744999602008-10-01T21:53:00.000-07:002008-10-01T21:56:00.970-07:00The str_repeat() function<div align="justify">This function is used to repeat printing a string a certain number of times.</div><div align="justify"><br />Syntax: str_repeat(string,count);</div><div align="justify"><br />string – the input string<br />count – the number of times the input string needs to be printed.</div><div align="justify"> </div><div align="justify">Example input:</div><div align="justify"> </div><div align="justify">echo str_repeat("*",10);</div><div align="justify"> </div><div align="justify">Example output:</div><div align="justify"> </div><div align="justify">**********</div><div align="justify"> </div><div align="justify">PS: This function could be used to create interesting patterns.</div>TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-49783480641224728432008-09-29T22:21:00.000-07:002008-09-29T22:23:36.240-07:00The strcmp() functionThe strcmp() function compares two strings and returns an integer accordingly.<br /><br />Syntax: strmp(string1,string2);<br /><br />This function returns 0 if both the strings are equal.<br />It returns a value less than zero, if string1 is less than string2.<br />It returns an integer greater than zero if string1 is greater than string2.<br /><br />Example input:<br /><br />$str1 = "Hello";<br />$str2 = "Halo";<br />echo strcmp($str1,$str2);<br /><br />Example output:<br /><br />1TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-79482458999050946172008-09-29T22:18:00.000-07:002008-09-29T22:21:21.934-07:00The implode() functionThe implode function is used to glue together elements of an array into a string.<br /><br />Syntax: implode([separator, ]array);<br /><br />separator - this parameter specifies the character or characters to be put between the array elements when they are glued together into a string. The default value is an empty space.<br /><br />array – the input array<br /><br />Example input:<br /><br />$employee = array('This', 'is','John.');<br />echo implode(" ",$employee);<br /><br />Example output:<br /><br />This is John.TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-54318099261009850792008-09-29T22:15:00.000-07:002008-09-29T22:18:52.935-07:00The explode() functionThe explode() function is used to split a string into an array.<br /><br />Syntax: explode(separator,string[,limit]);<br /><br />separator – the character or characters at which the string should be split.<br /><br />string – the input string<br /><br />limit – the maximum number of array elements you allow the string to be split into.<br /><br />Example inputs:<br /><br />1.<br />$str= "This is a simple program";<br />print_r(explode(" ",$str));<br /><br />2.<br />$str= "This is a simple program";<br />print_r(explode(" ",$str,3));<br /><br />Carefully note the difference in output between the two examples.<br /><br />Example outputs:<br /><br />1.<br />Array ( [0] => This [1] => is [2] => a [3] => simple [4] => program )<br /><br />2.<br />Array ( [0] => This [1] => is [2] => a simple program )TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com1tag:blogger.com,1999:blog-1980026666485776843.post-27453791966743164662008-09-23T22:14:00.000-07:002008-09-23T22:17:17.022-07:00The substr_replace() function<div align="justify">This function could be used to replace all or a portion of a string with another.</div><div align="justify"><br />Syntax: substr_replace(string,sub-string,start[,length]);</div><div align="justify"><br />sub-string – the string that replaces all or portion of the larger string.</div><div align="justify"><br />start – the position in the original string from where the replacement should start.</div><div align="justify"><br />If the start parameter is positive, the position is calculated from the beginning of the string.<br />If the start parameter is negative, the position is calculated from the end of the string.<br />A start parameter with the value zero would mean that the replacement should start from the first character of the string.</div><div align="justify"><br />length – the number of characters that should be replaced.</div><div align="justify"><br />A positive value for the length parameter indicates the number of characters to be replaced.<br />A negative value for the length parameter indicates the number of characters to be left at the end of the string.</div><div align="justify"> </div><div align="justify">Example input:</div><div align="justify"> </div><div align="justify">$str1="His name is James";<br />echo $str1;<br />echo "<br />";<br />echo $str2 = substr_replace($str1,"Her",0,3);<br />echo "<br />";<br />echo $str3 = substr_replace($str2,"Marie",-5);<br />echo "<br />";<br />echo substr_replace($str3," ",0,-5);</div><div align="justify"> </div><div align="justify">Example output:</div><div align="justify"> </div><div align="justify">His name is James</div><div align="justify">Her name is James</div><div align="justify">Her name is Marie </div><div align="justify">Marie</div>TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-4099834654905586882008-09-23T22:10:00.000-07:002008-09-23T22:13:12.998-07:00The substr_count() function<div align="justify">This function could be used to count the number of times a sub-string occurs within a given string.</div><div align="justify"><br />Syntax: substr_count(string,sub-string[,start,length]);</div><div align="justify"><br />sub-string- the string to be searched for<br />start – that position in the larger string from where the search should begin<br />length – length of the search from the starting position</div><div align="justify"><br />If start and length parameters are not specified, substr_count() carries out search in the entire string.</div><div align="justify"> </div><div align="justify">Example input:</div><div align="justify"> </div><div align="justify">$str1="This is a simple PHP program";<br />echo $str1;<br />echo "<br />";<br />echo substr_count($str1,"PHP",3,20);<br />echo "<br />";<br />echo substr_count($str1,"PHP",3,10);<br />echo "<br />";<br />echo substr_count($str1,"i");</div><div align="justify"> </div><div align="justify">Example output:</div><div align="justify"> </div><div align="justify">This is a simple PHP program 1 0 3</div>TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-22723573556663882692008-09-23T22:06:00.000-07:002008-09-23T22:09:04.582-07:00The strtok() function<div align="justify">This function could be used to split a string into smaller strings.</div><div align="justify"><br />Syntax: strtok(string,split);</div><div align="justify"><br />split – the split character</div><div align="justify"> </div><div align="justify">Example input:</div><div align="justify"> </div><div align="justify">$str1="This is a simple PHP program";<br />echo $str1;<br />echo "<br />";<br />echo $str2 = strtok($str1," ");<br />echo "<br />";<br />echo strtok(" ");<br />echo "<br />";<br />echo strtok(" ");</div><div align="justify"> </div><div align="justify">Example output:</div><div align="justify"> </div><div align="justify">This is a simple PHP program This is a</div><div align="justify"> </div><div align="justify"> </div><div align="justify">A good look at the example and you will realize that the string is specified only for the first time strtok() is called. For subsequent calls, the string need not be mentioned as the function keeps track of the current string.</div>TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-68113620970068289992008-09-19T22:59:00.000-07:002008-09-19T23:04:58.371-07:00The substr() functionThis function could be used to extract a certain part of the string.<br /><br />Syntax: substr(string,start[,length]);<br /><br />start – the starting position from where a sub-string should be extracted.<br />length – the number of characters the extracted string should contain.<br /><br />Both start and length can also contain negative values.<br /><br />A negative start parameter indicates that the position should be determined from the end of the string.<br /><br />A negative length parameter would extract the certain number of characters from the end of the string.<br /><br />If the length parameter is not specified, the rest of the string from the specified position would be returned.<br /><br />Example inputs:<br /><br />1.<br />$str1="This is a simple PHP program";<br />echo $str1;<br />echo "<br />";<br />echo substr($str1,17,3);<br />Here,the function returns the three characters after position 17 in $str1.<br /><br />2.<br />$str1="This is a simple PHP program";<br />echo $str1;<br />echo "<br />";<br />echo substr($str1,-17);<br /><br />3.<br />$str1="This is a simple PHP program";<br />echo $str1;<br />echo "<br />";<br />echo substr($str1,-17,-3);<br /><br />Example outputs:<br /><br />1.<br />This is a simple PHP program PHP <br />2.<br />This is a simple PHP program imple PHP program <br />3.<br />This is a simple PHP program imple PHP progTCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-36166087865665794702008-09-19T22:49:00.000-07:002008-09-19T22:58:55.524-07:00The strstr() functionThis function is used to identify the position of a string within a larger string.<br />If our search string is not found, this function returns FALSE.<br /><br />Syntax: strstr(string,search string);<br /><br />search string – the sub-string that is to be searched in the larger string.<br /><br />Example input:<br /><br />$str1="This is a simple PHP program";<br />echo $str1;<br />echo "<br />";<br />echo strstr($str1,"PHP");<br />echo "<br />";<br />echo strstr($str1,"p");<br /><br />Example output:<br /><br />This is a simple PHP program PHP program ple PHP programTCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-23922977375292535892008-09-18T22:02:00.001-07:002008-09-18T22:15:02.053-07:00The wordwrap() functionThis function wraps a string into a new line when it reaches a specified length.<br /><br />Syntax: wordwrap(string[,length,break,cut]);<br /><br />length – the number of characters after which the string is wrapped. The default length is 75.<br /><br />break – the character to be used as a separator. “\n” is the default.<br /><br />cut – If this is TRUE, words longer than the specified length will also be wrapped.<br /><br />If this value is FALSE, words longer than the specified length will not be wrapped. FALSE is the default value.<br /><br />Example inputs:<br /><br />1.<br />$str1="This is a simple PHP program";<br />echo $str1;<br />echo "<br />";<br />$str2 = wordwrap($str1,2,"<br/>",true);<br />echo $str2; <br /><br />2.<br />$str1="This is a simple PHP program";<br />echo $str1;<br />echo "<br />";<br />$str2 = wordwrap($str1,2,"<br/>");<br />echo $str2;<br /><br />In the second example, we have not mentioned any value for the cut parameter. The default value is FALSE and hence, words in the string that are longer than the specified length(here 2) will not be wrapped.<br /><br />Example outputs:<br /><br />1.<br />This is a simple PHP program Th is is a si mp le PH P pr og ra m <br /><br />2.<br />This is a simple PHP program This is a simple PHP programTCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0tag:blogger.com,1999:blog-1980026666485776843.post-72364837451889236252008-09-18T22:02:00.000-07:002008-09-18T22:12:03.799-07:00The addcslashes() functionThis function returns a string with backslashes added before certain characters.<br /><br />Syntax: addcslashes(string,characters);<br /><br />characters – the characters before which a backslash is to be added.<br /><br />Example inputs:<br /><br />1.<br />$str1=" my program";<br />echo $str1;<br />echo "<br />";<br />echo addcslashes($str1,"r");<br />echo "<br />";<br />echo addcslashes($str1,"r,m");<br /><br />2.<br />$str1=" my program";<br />echo $str1;<br />echo "<br />";<br />echo addcslashes($str1,"a...p");<br /><br />In this case, a backslash is added before every character that falls between a and p in the alphabetical sequence.<br /><br />3.<br />$str1=" 121232342434";<br />echo $str1;<br />echo "<br />";<br />echo addcslashes($str1,"1...3");<br /><br />Example outputs:<br /><br />1.<br />my program my p\rog\ram \my p\rog\ra\m <br /><br />2.<br />my program \my \pr\o\gr\a\m <br /><br />3.<br />121232342434 \1\2\1\2\3\2\34\24\34TCPhttp://www.blogger.com/profile/08853259634434554932noreply@blogger.com0