-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_strings.php
More file actions
59 lines (47 loc) · 1.79 KB
/
04_strings.php
File metadata and controls
59 lines (47 loc) · 1.79 KB
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
50
51
52
53
54
55
56
57
58
59
<?php
// Create simple string
$name = 'bikah';
$string = 'hello i am $name. i am 28';
$string2 = "hello i am $name. i am 28";
echo $string . '<br>';
echo $string2 . '<br>';
// String concatenation
echo 'hello' . 'world' . ' and php' . '<br>';
// String functions
// $string = " Hello World ";
// echo "1 - " . strlen($string) . '<br>' . PHP_EOL;
// echo "2 - " . trim($string) . '<br>' . PHP_EOL;
// echo "3 - " . ltrim($string) . '<br>' . PHP_EOL;
// echo "4 - " . rtrim($string) . '<br>' . PHP_EOL;
// echo "5 - " . str_word_count($string) . '<br>' . PHP_EOL;
// echo "6 - " . strrev($string) . '<br>' . PHP_EOL;
// echo "7 - " . strtoupper($string) . '<br>' . PHP_EOL;
// echo "8 - " . strtolower($string) . '<br>' . PHP_EOL;
// echo "9 - " . ucfirst('hello') . '<br>' . PHP_EOL;
// echo "10 - " . lcfirst('HELLO') . '<br>' . PHP_EOL;
// echo "11 - " . ucwords('hello world') . '<br>' . PHP_EOL;
// echo "12 - " . strpos($string, 'world') . '<br>' . PHP_EOL; // Change into world
// echo "13 - " . stripos($string, 'world') . '<br>' . PHP_EOL;
// echo "14 - " . substr($string, 8) . '<br>' . PHP_EOL;
// echo "15 - " . str_replace('World', 'PHP', $string) . '<br>' . PHP_EOL;
// echo "16 - " . str_ireplace('world', 'PHP', $string) . '<br>' . PHP_EOL;
// Multiline text and line breaks
$longText = "
hello,my name is Zura
i am 27,
i love my daughter
";
echo $longText . '<br>';
echo nl2br($longText) . '<br>';
// Multiline text and reserve html tags
$longText = "
hello,my name is <b>Zura</br
i am <b>27</b>,
i love my daughter
";
echo "1-" . $longText . '</br>';
echo "2-" . nl2br($longText) . '</br>';
echo "3-" . htmlentities($longText) . '</br>';
echo "4-" . nl2br(htmlentities($longText) . '</br>');
echo html_entity_decode('<b>zura</b>');
// https://www.php.net/manual/en/ref.strings.php