Posts

Showing posts with the label String

Strings in PHP, String Functions & Operations on Strings.

Image
String : String is a sequence of Characters. Strings Functions: 1. strlen();  --Returns the length of the String. Strlen() Function source code Length of "Hello World!". 2. strpos(); --Return the position of Substring or Second string in First String else return false. strpos() string position function output of the function 3. strrev(); --Reverse the entered String. Reverse the string strrev() source code Output of original string along with revered string 4. str_word_count(); --Return the Worlds in String Space Separated. str_word_count() return the output total number of word in string. output of the above code. 5. str_replace(); --Function replace the first parameter,with second from third String.      Source Code of str_replace() output of above code.                © 2015 Rajendra Kumar Yadav Learn Computer Tricks and Programming & Learn PHP

Assignment 1 Question 2 (Server Side Scripting Part using PHP).

<?php /* @autor Rajendra Kumar Yadav @Check the Substring position @Check First and last occurance Position @ Replace Small Substring with some new substring. */ $n=$_POST['str1']; $n1=$_POST['str2']; $n2=$_POST['str3']; $ch=$_POST['ch']; function POSITION($n,$n1) { $c=strpos($n,$n1); $c1=strrpos($n,$n1); echo "The Substring 2 Occurs at position ".$c." and ".$c1; } function OCCUR_SUBSTR($n,$n1) { $c2=substr_count($n,$n1); echo "The Substring ".$n1 ." occured ".$c2." times."; } if($ch=="first_last_pos") { POSITION($n,$n1); } if($ch=="occ_substring") { OCCUR_SUBSTR($n,$n1); } function REPLACER($n,$n1,$n2) { $c3=strlen($n1); $c4=substr_replace($n,$n2,$c,$c3); echo "First String is ".$n; echo "Second String is ".$n1; echo "New String is ".$n2; } if($ch==...