1
+ <?php
2
+ $ title = "Strings Manupulations " ;
3
+ include 'includes/header.php ' ;
4
+ ?>
5
+ <h1><center>PHP String Manipulation</center></h1>
6
+
7
+ <?php
8
+ // Concatenation of Strings
9
+ $ phrase1 = "student who came late " ;
10
+ $ phrase2 = "in class, stand with Rock " ;
11
+ echo $ phrase1 . ", name Faizee, " . $ phrase2 ;
12
+ echo '<br> ' ;
13
+ echo '<hr> ' ;
14
+
15
+ // String transformation
16
+ $ name = "faizee asad " ;
17
+ echo 'Uppercase first latter: ' . ucfirst ($ name ) . '<br> ' ;
18
+ echo 'Uppercase first latter of each word: ' . ucwords ($ name ) . '<br> ' ;
19
+ echo 'Upper case : ' . strtoupper ($ name ) . '<br> ' ;
20
+ echo 'Lower case : ' . strtolower ("FAIZEE ASAD " ) . '<br> ' ;
21
+ echo '<hr> ' ;
22
+ echo 'Repeat String: ' . str_repeat ('a ' ,10 ). '<br> ' ;
23
+ echo 'Repeat String: ' . strtoupper (str_repeat ('a ' ,10 )). '<br> ' ;
24
+ echo 'Get a Substring ' . substr ($ name ,3 , 4 ). '<br> ' ;
25
+ echo 'Get position of String: ' . strpos ($ name ,'f ' );
26
+ echo '<br> ' ;
27
+ echo 'Get position of String: ' . strpos ($ name ,'z ' );
28
+ echo '<br> ' ;
29
+ // Returns NULL
30
+ // echo 'Get position of string: ' . strpos($combine, 'h') . '<br>';
31
+
32
+ echo 'Find Charater "f": ' . strchr ($ name , 'f ' ). '<br> ' ;
33
+ echo 'Find Charater "a": ' . strchr ($ name , 'a ' ). '<br> ' ;
34
+ echo 'Find Charater "z": ' . strchr ($ name , 'z ' ). '<br> ' ;
35
+ echo 'Find Charater "s": ' . strchr ($ name , 's ' ). '<br> ' ;
36
+
37
+ echo 'Find Lenght of String: ' . strlen ($ name ) . '<br> ' ;
38
+
39
+ echo 'Without Trim: ' . "A " . " B C D " . "E " . '<br> ' ;
40
+ echo 'Trim spaces on both sides: ' . "A " . trim (" B C D " ) . "E " . '<br> ' ;
41
+ echo 'Trim spaces to the left: ' . "A " . ltrim (" B C D " ) . "E " . '<br> ' ;
42
+ echo 'Trim spaces to the right: ' . "A " . rtrim (" B C D " ) . "E " . '<br> ' ;
43
+
44
+ echo 'Replace string with another: ' . str_replace ("stand " , "sit " , $ phrase2 ) . '<br> ' ;
45
+ echo '<hr> ' ;
46
+
47
+ ?>
48
+ <?php require 'includes/footer.php ' ?>
0 commit comments