-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_string_functions.php
More file actions
49 lines (33 loc) · 907 Bytes
/
Copy path08_string_functions.php
File metadata and controls
49 lines (33 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
$string = "Hello World";
//get length of a string
// echo strlen($string);
//find first occurrence
// echo strpos($string,'o');
//find last occurence
// echo strrpos($string,'o');
//reverse
// echo strrev($string);
//convert to lower case
// echo strtolower($string);
//convert to upper
// echo strtoupper($string);
//upper case first character of each word
// echo ucwords($string);
//string replace
// echo str_replace('World','Everyone',$string);
//return a portion of the string specified by the offset and length
// echo substr($string,0,5);
// echo substr($string,5);
// if(str_starts_with($string,'Hello')){
// echo 'YES';
// }
//ends with
// if(str_ends_with($string,'ld')){
// echo 'YES';
// }
// $string2 = '<h1>Hello</h1>';
$string2 = '<script>alert(1)</script>';
// echo htmlspecialchars($string2);
// printf('%s likes to %s','Brad','Code');
printf('1+1=%f',1+1);