Priklady/03/Funkcia_substr.php
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
2 <html>
3 <head>
4 <title>Funkcia </title>
5 <meta http-equiv="Author" content="Imrich BURANSKY" />
6 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1250" />
7 </head>
8 <body> <div>
9 <h3>Funkcia substr</h3>
10 Funkcia substr slúi na získanie časti textového reazca:
11 <h4>string substr (string text, int start [, int length])</h4>
12
13 <?php
14 echo 'Volaním <b>substr("abcdef", 1)</b> získame <b>',
15 substr("abcdef", 1), "</b><br />\n";
16
17 echo 'Volaním <b>substr("abcdef", 1, 3)</b> získame <b>',
18 substr("abcdef", 1, 3), "</b><br/>\n";
19
20 echo 'Volaním <b>substr("abcdef", 2, -1)</b> získame <b>',
21 substr("abcdef", 2, -1), "</b><br />\n";
22
23 echo 'Volaním <b>substr("abcdef", 7)</b> získame <b>',
24 substr("abcdef", 7), "</b><br /><br />\n";
25
26 echo 'Volaním <b>substr("abcdef", -1)</b> získame <b>',
27 substr("abcdef", -1), "</b><br />\n";
28
29 echo 'Volaním <b>substr("abcdef", -3)</b> získame <b>',
30 substr("abcdef", -3), "</b><br />\n";
31
32 echo 'Volaním <b>substr("abcdef", -3, 2)</b> získame <b>',
33 substr("abcdef", -3, 2), "</b><br />\n";
34
35 echo 'Volaním <b>substr("abcdef", -3, -2)</b> získame <b>',
36 substr("abcdef", -3, -2), "</b>\n";
37
38 ?>
39 </div></body>
40 </html>