Tutorials about PHP, MySQL, HTML/HTML5, CSS, SEO, GIMP, Instagram, TikTok, Canva.
Pretrazite Blog // Search This Blog
Wednesday, February 17, 2016
Tuesday, February 16, 2016
Prolaz kroz niz (Loop through array)
Kroz niz mozete da prodjete pomocu funkcije count(), koja odredjuje koliko se elemenata nalazi u nizu.
Primer:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
for ($indeks = 0; $indeks < count($motor); $indeks++) {
echo $motor[$indeks], "<br />";
}
?>
Rezultat:
suzuki
ktm
honda
Funkcija koja prikazuje element niza je funkcija print_r().
Primer 2:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
print_r($motor);
?>
Rezultat:
Array ( [0] => suzuki [1] => ktm [2] => honda )
Za prolaz kroz kolekcije kao sto su nizovi koristite iskaz foreach. Ovaj iskaz ima dva oblika:
foreach (izraz_niza as $vrednost) iskaz
Ovaj oblik dodeljuje promenljivoj $vrednost vrednost sledeceg elementa iz niza pri svakom prolazu kroz petlju.
foreach (izraz_niza as $kljuc => $vrednost) iskaz
Ovaj oblik postavlja kljuc tekuceg elementa (tj. indeks), u promenljivu $kljuc i to radi za svaki prolaz kroz petlju.
Primer 3: prikaz svih elemenata niza pomocu iskaza foreach.
<?php
$motor = array("suzuki", "ktm", "honda");
foreach ($motor as $vrednost) {
echo "Vrednost: $vrednost<br />";
}
?>
Rezultat:
Vrednost: suzuki
Vrednost: ktm
Vrednost: honda
Primer 4: prikaz i kljuceva i vrednosti niza.
<?php
$motor = array("suzuki", "ktm", "honda");
foreach ($motor as $kljuc => $vrednost) {
echo "Kljuc: $kljuc; Vrednost: $vrednost<br />";
}
?>
Rezultat:
Kljuc: 0; Vrednost: suzuki
Kljuc: 1; Vrednost: ktm
Kljuc: 2; Vrednost: honda
Pomocu petlje while takodje mozete da prodjete kroz niz, sa funkcijom each(). Ova funkcija se koristi za prolaz kroz kolekcije (tj. nizove). Funkcija each us vakom prolazu vraca kljuc tekuceg elementa , a onda prelazi na sledeci element. Ako zelite da rukujete visestrukim vrednostima koje se dobijaju iz niza, mozete da koristite funkciju list(). Ova funkcija dve povratne vrednosti dodeljuje posebnim promenljivama.
Primer 5:
<?php
$motor = array("suzuki", "ktm", "honda");
while (list($kljuc, $vrednost) = each($motor)) {
echo "Kljuc: $kljuc; Vrednost: $vrednost<br />";
}
?>
Rezultat:
Kljuc: 0; Vrednost: suzuki
Kljuc: 1; Vrednost: ktm
Kljuc: 2; Vrednost: honda
Through array you can pass with function count(), which specifies how many elements are in the array.
Example:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
for ($index = 0; $index < count($motorcycle); $index++) {
echo $motorcycle[$index], "<br />";
}
?>
Result:
suzuki
ktm
honda
The function that displays the array element is a function print_r().
Example 2:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
print_r($motorcycle);
?>
Result:
Array ( [0] => suzuki [1] => ktm [2] => honda )
For passing through collections such as arrays you can use foreach statement. This statement has two forms:
foreach (expression_array as $value) statement
This type assigns to the variable $value value of next element from array on each pass through the loop.
foreach (expression_array as $key => $value) statement
This form sets the key of the current element (ie, index) in the variable $key and it works for each pass through the loop.
Example 3: display of all elements of the array using the statement foreach.
<?php
$motorcycle = array("suzuki", "ktm", "honda");
foreach ($motorcycle as $value) {
echo "Value: $value<br />";
}
?>
Result:
Value: suzuki
Value: ktm
Value: honda
Example 4: display of keys and values of an array.
<?php
$motorcycle = array("suzuki", "ktm", "honda");
foreach ($motorcycle as $key => $value) {
echo "Key: $key; Value: $value<br />";
}
?>
Result:
Key: 0; Value: suzuki
Key: 1; Value: ktm
Key: 2; Value: honda
With while loop you can also pass through array, with function each(). This function is used to pass through the collection (ie. arrays). The function each in each pass returns the key of the current element, and then moves on to the next element. If you want to handle multiple values that come from array, you can use the function list(). This function, two returned values assigns to special variables.
Example 5:
<?php
$motorcycle = array("suzuki", "ktm", "honda");
while (list($key, $value) = each($motorcycle)) {
echo "Key: $key; Value: $value<br />";
}
?>
Result:
Key: 0; Value: suzuki
Key: 1; Value: ktm
Key: 2; Value: honda
Primer:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
for ($indeks = 0; $indeks < count($motor); $indeks++) {
echo $motor[$indeks], "<br />";
}
?>
Rezultat:
suzuki
ktm
honda
Funkcija koja prikazuje element niza je funkcija print_r().
Primer 2:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
print_r($motor);
?>
Rezultat:
Array ( [0] => suzuki [1] => ktm [2] => honda )
Za prolaz kroz kolekcije kao sto su nizovi koristite iskaz foreach. Ovaj iskaz ima dva oblika:
foreach (izraz_niza as $vrednost) iskaz
Ovaj oblik dodeljuje promenljivoj $vrednost vrednost sledeceg elementa iz niza pri svakom prolazu kroz petlju.
foreach (izraz_niza as $kljuc => $vrednost) iskaz
Ovaj oblik postavlja kljuc tekuceg elementa (tj. indeks), u promenljivu $kljuc i to radi za svaki prolaz kroz petlju.
Primer 3: prikaz svih elemenata niza pomocu iskaza foreach.
<?php
$motor = array("suzuki", "ktm", "honda");
foreach ($motor as $vrednost) {
echo "Vrednost: $vrednost<br />";
}
?>
Rezultat:
Vrednost: suzuki
Vrednost: ktm
Vrednost: honda
Primer 4: prikaz i kljuceva i vrednosti niza.
<?php
$motor = array("suzuki", "ktm", "honda");
foreach ($motor as $kljuc => $vrednost) {
echo "Kljuc: $kljuc; Vrednost: $vrednost<br />";
}
?>
Rezultat:
Kljuc: 0; Vrednost: suzuki
Kljuc: 1; Vrednost: ktm
Kljuc: 2; Vrednost: honda
Pomocu petlje while takodje mozete da prodjete kroz niz, sa funkcijom each(). Ova funkcija se koristi za prolaz kroz kolekcije (tj. nizove). Funkcija each us vakom prolazu vraca kljuc tekuceg elementa , a onda prelazi na sledeci element. Ako zelite da rukujete visestrukim vrednostima koje se dobijaju iz niza, mozete da koristite funkciju list(). Ova funkcija dve povratne vrednosti dodeljuje posebnim promenljivama.
Primer 5:
<?php
$motor = array("suzuki", "ktm", "honda");
while (list($kljuc, $vrednost) = each($motor)) {
echo "Kljuc: $kljuc; Vrednost: $vrednost<br />";
}
?>
Rezultat:
Kljuc: 0; Vrednost: suzuki
Kljuc: 1; Vrednost: ktm
Kljuc: 2; Vrednost: honda
Through array you can pass with function count(), which specifies how many elements are in the array.
Example:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
for ($index = 0; $index < count($motorcycle); $index++) {
echo $motorcycle[$index], "<br />";
}
?>
Result:
suzuki
ktm
honda
The function that displays the array element is a function print_r().
Example 2:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
print_r($motorcycle);
?>
Result:
Array ( [0] => suzuki [1] => ktm [2] => honda )
For passing through collections such as arrays you can use foreach statement. This statement has two forms:
foreach (expression_array as $value) statement
This type assigns to the variable $value value of next element from array on each pass through the loop.
foreach (expression_array as $key => $value) statement
This form sets the key of the current element (ie, index) in the variable $key and it works for each pass through the loop.
Example 3: display of all elements of the array using the statement foreach.
<?php
$motorcycle = array("suzuki", "ktm", "honda");
foreach ($motorcycle as $value) {
echo "Value: $value<br />";
}
?>
Result:
Value: suzuki
Value: ktm
Value: honda
Example 4: display of keys and values of an array.
<?php
$motorcycle = array("suzuki", "ktm", "honda");
foreach ($motorcycle as $key => $value) {
echo "Key: $key; Value: $value<br />";
}
?>
Result:
Key: 0; Value: suzuki
Key: 1; Value: ktm
Key: 2; Value: honda
With while loop you can also pass through array, with function each(). This function is used to pass through the collection (ie. arrays). The function each in each pass returns the key of the current element, and then moves on to the next element. If you want to handle multiple values that come from array, you can use the function list(). This function, two returned values assigns to special variables.
Example 5:
<?php
$motorcycle = array("suzuki", "ktm", "honda");
while (list($key, $value) = each($motorcycle)) {
echo "Key: $key; Value: $value<br />";
}
?>
Result:
Key: 0; Value: suzuki
Key: 1; Value: ktm
Key: 2; Value: honda
Monday, February 15, 2016
HTML elements - lists and tables
The lists are used for specifying a set of items. They can be ordered, unordered or definition.
For an ordered list is used <ol> tag and each item in this list will be preceded by a regular number, while for unordered list is used <ul> tag. Each item in any of these two types of lists should be placed within the <li> tag. For definition lists is used <dl> tag. These lists, in addition to citing the general items, contain a description of each item, to be placed within the <dd> tag, and the item is placed within the <dt> tag.
For example, ordered and unordered list.
<!DOCTYPE html>
<html>
<head>
<title>HTML elements - lists and tables</title>
<meta charset="UTF-8"/>
<meta name="description" content="This page is about HTML elements - lists and tables" />
<meta name="keywords" content="HTML elements, lists, tables, html lists, html tables" />
<meta name="author" content="Marija Rikic">
<link rel="icon" type="image/png" href="images/favicon.jpg">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/script.js"></script>
<!-- JavaScript that is inserted directly on the page -->
<script type="text/javascript">
</script>
<noscript>Your browser does not support JavaScript</noscript>
</head>
<body>
<h2>Lists</h2>
<h3>Ordered and Unordered Lists</h3>
<ol>
<li>Suzuki</li>
<li>KTM</li>
<li>Honda</li>
</ol>
<ul>
<li>Ducati</li>
<li>Kawasaki</li>
<li>Yamaha</li>
</ul>
<h3>Definition Lists</h3>
<dl>
<dt>HTML</dt>
<dd>Language for defining the structure of a web page.</dd>
<dt>CSS</dt>
<dd>Language for defining the layout of web page.</dd>
<dt>JavaScript</dt>
<dd>Language for implementation functionality of web page.</dd>
</dl>
</body>
</html>
Save this code as lists.html.
Next code save as style.css.
body {
background-color: #A1D490;
}
h1 {
color: orange;
text-align: left;
}
h2 {
color: green;
text-align: left;
}
h3 {
color: black;
}
To select a color, you can use the color picker.
Result:
Example 2:
<!DOCTYPE html>
<html>
<head>
<title>HTML elements - tables</title>
<meta charset="UTF-8"/>
<meta name="description" content="This page is about HTML element - tables" />
<meta name="keywords" content="HTML elements, html tables" />
<meta name="author" content="Marija Rikic">
<link rel="icon" type="image/png" href="images/favicon.jpg">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/script.js"></script>
<!-- JavaScript that is inserted directly on the page -->
<script type="text/javascript">
</script>
<noscript>Your browser does not support JavaScript</noscript>
</head>
<body>
<table style="width:20%">
<thead>
<tr>
<th>#</th>
<th>Month</th>
<th>Day</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>January</td>
<td>31</td>
</tr>
<tr>
<td>2</td>
<td>February</td>
<td>28</td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td>Total</td>
<td>59</td>
</tr>
</tfoot>
</table>
</body>
</html>
Save this code as table.html.
Add next code in style.css.
table, th, td {
border: 1px solid black;
text-align: left;
}
Result:
Note: the table should contain only tabular data, and not to be used for the organization of content inside the web page.
Complete code used in examples.
For an ordered list is used <ol> tag and each item in this list will be preceded by a regular number, while for unordered list is used <ul> tag. Each item in any of these two types of lists should be placed within the <li> tag. For definition lists is used <dl> tag. These lists, in addition to citing the general items, contain a description of each item, to be placed within the <dd> tag, and the item is placed within the <dt> tag.
For example, ordered and unordered list.
<!DOCTYPE html>
<html>
<head>
<title>HTML elements - lists and tables</title>
<meta charset="UTF-8"/>
<meta name="description" content="This page is about HTML elements - lists and tables" />
<meta name="keywords" content="HTML elements, lists, tables, html lists, html tables" />
<meta name="author" content="Marija Rikic">
<link rel="icon" type="image/png" href="images/favicon.jpg">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/script.js"></script>
<!-- JavaScript that is inserted directly on the page -->
<script type="text/javascript">
</script>
<noscript>Your browser does not support JavaScript</noscript>
</head>
<body>
<h2>Lists</h2>
<h3>Ordered and Unordered Lists</h3>
<ol>
<li>Suzuki</li>
<li>KTM</li>
<li>Honda</li>
</ol>
<ul>
<li>Ducati</li>
<li>Kawasaki</li>
<li>Yamaha</li>
</ul>
<h3>Definition Lists</h3>
<dl>
<dt>HTML</dt>
<dd>Language for defining the structure of a web page.</dd>
<dt>CSS</dt>
<dd>Language for defining the layout of web page.</dd>
<dt>JavaScript</dt>
<dd>Language for implementation functionality of web page.</dd>
</dl>
</body>
</html>
Save this code as lists.html.
Next code save as style.css.
body {
background-color: #A1D490;
}
h1 {
color: orange;
text-align: left;
}
h2 {
color: green;
text-align: left;
}
h3 {
color: black;
}
To select a color, you can use the color picker.
Result:
Tables
The table is represented with the <table> tag, which can contain any number of table rows, ie. <tr> tags. Each row contains the cells that contain data and which are marked with <td> tags. Each table has three main sections:- table header (<thead> </ thead>) where there is, usually, a single row of cells that represent titles with columns <th>.
- table body (<tbody> </ tbody>) that contains rows that contain cells with data.
- table footer (<tfoot> </ tfoot>), which is used to summarize the data. Footer if it is not necessary very often is omitted.
Example 2:
<!DOCTYPE html>
<html>
<head>
<title>HTML elements - tables</title>
<meta charset="UTF-8"/>
<meta name="description" content="This page is about HTML element - tables" />
<meta name="keywords" content="HTML elements, html tables" />
<meta name="author" content="Marija Rikic">
<link rel="icon" type="image/png" href="images/favicon.jpg">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/script.js"></script>
<!-- JavaScript that is inserted directly on the page -->
<script type="text/javascript">
</script>
<noscript>Your browser does not support JavaScript</noscript>
</head>
<body>
<table style="width:20%">
<thead>
<tr>
<th>#</th>
<th>Month</th>
<th>Day</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>January</td>
<td>31</td>
</tr>
<tr>
<td>2</td>
<td>February</td>
<td>28</td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td>Total</td>
<td>59</td>
</tr>
</tfoot>
</table>
</body>
</html>
Save this code as table.html.
Add next code in style.css.
table, th, td {
border: 1px solid black;
text-align: left;
}
Result:
Note: the table should contain only tabular data, and not to be used for the organization of content inside the web page.
Complete code used in examples.
Base of HTML5 web page
This base of HTML5 web page, that I will be using in examples.
<!DOCTYPE html>
<html>
<head>
<title>Title of document</title>
<meta charset="UTF-8"/>
<meta name="description" content="Description that search reads" />
<meta name="keywords" content="page keywords, keywords" />
<meta name="author" content="Marija Rikic">
<link rel="icon" type="image/png" href="images/favicon.jpg">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/script.js"></script>
<!-- JavaScript that is inserted directly on the page -->
<script type="text/javascript">
</script>
<noscript>Your browser does not support JavaScript</noscript>
</head>
<body>
</body>
</html>
Save this file as base.html.
<!DOCTYPE html>
<html>
<head>
<title>Title of document</title>
<meta charset="UTF-8"/>
<meta name="description" content="Description that search reads" />
<meta name="keywords" content="page keywords, keywords" />
<meta name="author" content="Marija Rikic">
<link rel="icon" type="image/png" href="images/favicon.jpg">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/script.js"></script>
<!-- JavaScript that is inserted directly on the page -->
<script type="text/javascript">
</script>
<noscript>Your browser does not support JavaScript</noscript>
</head>
<body>
</body>
</html>
Save this file as base.html.
Sunday, February 14, 2016
Brisanje elemenata iz niza (Removing elements from array)
U sledecem primeru, element se ne brise vec se u njemu skladisti prazan string.
Primer:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
$motor[1] = "";
for ($indeks = 0; $indeks < count($motor); $indeks++) {
echo $motor[$indeks], "<br />";
}
?>
Sacuvajte ovaj fajl kao brisanje-elemenata-iz-niza.php.
Rezultat:
suzuki
honda
Ako zelite da iz niz obrisete niz, koristite funkciju unset().
unset($vrednost[1]);
Primer 2:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
unset($motor[1]);
for ($indeks = 0; $indeks < count($motor); $indeks++) {
echo $motor[$indeks], "<br />";
}
?>
Objasnjenje: ako sada pokusate da prikazete element koji je izbacen dobicete upozorenje.
Rezultat:
suzuki
Notice: Undefined offset: 1 in C:\xampp2\htdocs\PHPtuts\brisanje-elemenata-iz-niza.php on line 34
In the following example, the element is not deleted but empty string is stored in it..
Example:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
$motorcycle[1] = "";
for ($index = 0; $index< count($motorcycle); $index++) {
echo $motorcycle[$index], "<br />";
}
?>
Save this file as removing-elements-from-array.php.
Result:
suzuki
honda
If you want to delete array from array, use the function unset().
unset ($value [1]);
Example 2:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
unset($motorcycle[1]);
for ($index = 0; $index < count($motorcycle); $index++) {
echo $motorcycle[$index], "<br />";
}
?>
Explanation: if you now try to display an element that was removed you'll get a warning.
Result:
suzuki
Notice: Undefined offset: 1 in C:\xampp2\htdocs\PHPtuts\removing-elements-from-array.php on line 34
Primer:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
$motor[1] = "";
for ($indeks = 0; $indeks < count($motor); $indeks++) {
echo $motor[$indeks], "<br />";
}
?>
Sacuvajte ovaj fajl kao brisanje-elemenata-iz-niza.php.
Rezultat:
suzuki
honda
Ako zelite da iz niz obrisete niz, koristite funkciju unset().
unset($vrednost[1]);
Primer 2:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
unset($motor[1]);
for ($indeks = 0; $indeks < count($motor); $indeks++) {
echo $motor[$indeks], "<br />";
}
?>
Objasnjenje: ako sada pokusate da prikazete element koji je izbacen dobicete upozorenje.
Rezultat:
suzuki
Notice: Undefined offset: 1 in C:\xampp2\htdocs\PHPtuts\brisanje-elemenata-iz-niza.php on line 34
In the following example, the element is not deleted but empty string is stored in it..
Example:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
$motorcycle[1] = "";
for ($index = 0; $index< count($motorcycle); $index++) {
echo $motorcycle[$index], "<br />";
}
?>
Save this file as removing-elements-from-array.php.
Result:
suzuki
honda
If you want to delete array from array, use the function unset().
unset ($value [1]);
Example 2:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
unset($motorcycle[1]);
for ($index = 0; $index < count($motorcycle); $index++) {
echo $motorcycle[$index], "<br />";
}
?>
Explanation: if you now try to display an element that was removed you'll get a warning.
Result:
suzuki
Notice: Undefined offset: 1 in C:\xampp2\htdocs\PHPtuts\removing-elements-from-array.php on line 34
Wednesday, February 10, 2016
HTML and the basic structure of a web page
HTML represents the structure of data to be displayed to the user.
Example of text in HTML format and the basic structure of a web page.
<!DOCTYPE html>
<html>
<head>
<title>Basic structure of a web page</title>
</head>
<body>
<h1>This is title</h1>
<p>First paragraph of text.</p>
<p>Second paragraph of text.</p>
<h2>This is subtitle</h2>
<p>Third paragraph of text.</p>
</body>
</html>
Save this file as index.html.
<!DOCTYPE html> is the declaration of a document that indicates to the browser what kind of the document can expect. This declaration defines that the HTML code on the page is according to the HTML5 standards.
Each HTML page is surrounded by HTML tags, <html> </html>. Each page has two parts, the header and body. The header is surrounded by head tags, <head>
</ head>, and body with body tags, <body> </body>.
In HTML, each text is surrounded by the start and end tags. Tags are keywords surrounded by the signa <> and the </>. <> is the start tag, and </> is the end tag. Almost always they should be used in pairs (there are some exceptions, such link and meta elements). Tags give meaning to the content that is contained in them and dictate the manner in which the browser will display it.
<title>Title that is displayed in browser</title>
<meta charset="UTF-8"/>
<meta name="description" content="Description that search reads" />
<meta name="keywords" content="page keywords, keywords" />
<meta name="author" content="Marija Rikic">
<link rel="icon" type="image/png" href="images/favicon.jpg">
<link rel="stylesheet" type="text/css" href="css/style.css">
<!-- CSS styles that are inserted directly on the page -->
<style type="text/css">
p {color:darkviolet;}
</style>
<script type="text/javascript" src="js/script.js"></script>
<!-- JavaScript that is inserted directly on the page -->
<script type="text/javascript">
</script>
<noscript>Your browser does not support JavaScript</noscript>
</head>
Header of HTML page contains a few elements such as title, meta, link, style, script, noscript. Title element is essential so that a web page is valid, and all others are optional.
Element title contains the text to be displayed as a page title (inscription in tab) of web browser in which the page is open. Title should contain substantially description ie. the purpose of the page, or what somebody should type in the search box in order to come to that page. Title should not be too long, because the search engines take into account only a certain number of characters, and the rest is ignored. The optimal length for search engines is between 55-60 characters.
Note: you should not use the same title for several different pages. In the title highlight why they are unique and which useful information they provide so that they wouldn't counteract with each other for the same criteria.
Meta elements contain information about the document and will not be displayed on the page. These are charset - attribute specifies the character encoding for the HTML document, page description, keyword information, the author of the page. Web search engines such as Google, Bing and Yahoo can use descriptiion meta tag as the description that appears in the listing of search results.
Keyword meta tag which should contain keywords of the page, is no longer so important Google in 2009 excluded the use of keywords meta tag.
Link elements are used for the inclusion of external resources. This element is always empty, contains only attributes and no end tag. In an HTML document can be set up any number of <link> element.
Style elements serve to specify styles within them, by which to define how the content will be displayed. An HTML document may contain more than one <style> element.
Script element is used to store the code, usually JavaScript, which is executed in the browser. This code can be indicated in the script tags <script> </script> or to be included as an external file (js/script.js). If you include it as an external file, script element must be empty and must have a src attribute that points to the location of resource.
Noscript element is used to define the content that will be displayed to users if the scripts are not supported or if their web browser is set to not allow the use of scripts.
<body>
<h1>Basic structure of a web page</h1>
<p>Paragraph of text with a link <a href="second-page.html">to second page</a>.</p>
<p>Paragraph of text <br />with two rows.</p>
<h2>This is subtitle</h2>
<p>Paragraph of text with image <img src="images/mr-logo.png" alt="logo" title="freelance web developer" />.</p>
</body>
The body of HTML page contains structured information that is displayed to the user in a web browser. There are six different HTML headings: h1, h2, h3, h4, h5, h6. Paragraphs may contain plain text or other tags. In this example, you can see <br /> tag, that text wraps to a new row, or <img> tag, which is used for inserting images, or link (to second page) that allows the user to click on text link that leads directly to another page.
Complete code used in examples.
Example of text in HTML format and the basic structure of a web page.
<!DOCTYPE html>
<html>
<head>
<title>Basic structure of a web page</title>
</head>
<body>
<h1>This is title</h1>
<p>First paragraph of text.</p>
<p>Second paragraph of text.</p>
<h2>This is subtitle</h2>
<p>Third paragraph of text.</p>
</body>
</html>
Save this file as index.html.
<!DOCTYPE html> is the declaration of a document that indicates to the browser what kind of the document can expect. This declaration defines that the HTML code on the page is according to the HTML5 standards.
Each HTML page is surrounded by HTML tags, <html> </html>. Each page has two parts, the header and body. The header is surrounded by head tags, <head>
</ head>, and body with body tags, <body> </body>.
In HTML, each text is surrounded by the start and end tags. Tags are keywords surrounded by the signa <> and the </>. <> is the start tag, and </> is the end tag. Almost always they should be used in pairs (there are some exceptions, such link and meta elements). Tags give meaning to the content that is contained in them and dictate the manner in which the browser will display it.
Header of page
<head><title>Title that is displayed in browser</title>
<meta charset="UTF-8"/>
<meta name="description" content="Description that search reads" />
<meta name="keywords" content="page keywords, keywords" />
<meta name="author" content="Marija Rikic">
<link rel="icon" type="image/png" href="images/favicon.jpg">
<link rel="stylesheet" type="text/css" href="css/style.css">
<!-- CSS styles that are inserted directly on the page -->
<style type="text/css">
p {color:darkviolet;}
</style>
<script type="text/javascript" src="js/script.js"></script>
<!-- JavaScript that is inserted directly on the page -->
<script type="text/javascript">
</script>
<noscript>Your browser does not support JavaScript</noscript>
</head>
Header of HTML page contains a few elements such as title, meta, link, style, script, noscript. Title element is essential so that a web page is valid, and all others are optional.
Element title contains the text to be displayed as a page title (inscription in tab) of web browser in which the page is open. Title should contain substantially description ie. the purpose of the page, or what somebody should type in the search box in order to come to that page. Title should not be too long, because the search engines take into account only a certain number of characters, and the rest is ignored. The optimal length for search engines is between 55-60 characters.
Note: you should not use the same title for several different pages. In the title highlight why they are unique and which useful information they provide so that they wouldn't counteract with each other for the same criteria.
Meta elements contain information about the document and will not be displayed on the page. These are charset - attribute specifies the character encoding for the HTML document, page description, keyword information, the author of the page. Web search engines such as Google, Bing and Yahoo can use descriptiion meta tag as the description that appears in the listing of search results.
Keyword meta tag which should contain keywords of the page, is no longer so important Google in 2009 excluded the use of keywords meta tag.
Link elements are used for the inclusion of external resources. This element is always empty, contains only attributes and no end tag. In an HTML document can be set up any number of <link> element.
Style elements serve to specify styles within them, by which to define how the content will be displayed. An HTML document may contain more than one <style> element.
Script element is used to store the code, usually JavaScript, which is executed in the browser. This code can be indicated in the script tags <script> </script> or to be included as an external file (js/script.js). If you include it as an external file, script element must be empty and must have a src attribute that points to the location of resource.
Noscript element is used to define the content that will be displayed to users if the scripts are not supported or if their web browser is set to not allow the use of scripts.
<body>
<h1>Basic structure of a web page</h1>
<p>Paragraph of text with a link <a href="second-page.html">to second page</a>.</p>
<p>Paragraph of text <br />with two rows.</p>
<h2>This is subtitle</h2>
<p>Paragraph of text with image <img src="images/mr-logo.png" alt="logo" title="freelance web developer" />.</p>
</body>
The body of HTML page contains structured information that is displayed to the user in a web browser. There are six different HTML headings: h1, h2, h3, h4, h5, h6. Paragraphs may contain plain text or other tags. In this example, you can see <br /> tag, that text wraps to a new row, or <img> tag, which is used for inserting images, or link (to second page) that allows the user to click on text link that leads directly to another page.
Complete code used in examples.
Izmena nizova (Modification of arrays)
Ako ste vec napravili niz, postoji mogucnost promene vrednosti u nizu. Jedan od nacina je da elementu niza pristupite pomocu indeksa.
Primer: ako zelite da vrednost za $motor[3] promenite na "ducati".
<?php
$motor[1] = "suzuki";
$motor[2] = "ktm";
$motor[3] = "honda";
$motor[3] = "ducati";
?>
Rezultat:
ducati
Ako posle toga zelite da dodate novi element "kawasaki" i da on treba da ide na kraj niza. Ovo mozete da uradite pomocu precice za dodavanje novog elementa, a to je iskaz $motor[].
Primer 2:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
$motor[2] = "ducati";
$motor[] = "kawasaki";
?>
Da prikazete sadrzaj treba da prodjete kroz niz.
Primer 3:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
$motor[2] = "ducati";
$motor[] = "kawasaki";
for ($indeks = 0; $indeks < count($motor); $indeks++) {
echo $motor[$indeks], "<br />";
}
?>
Rezultat:
suzuki
ktm
ducati
kawasaki
Ako zelite mozete i da ceo niz kopirate u drugi niz.
Primer 4:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
$motor[2] = "ducati";
$motor[] = "kawasaki";
$italijaProizvodi = $motor;
echo $italijaProizvodi[2];
?>
Rezultat:
ducati
If you have already made array, there is a possibility to change the value in the array. One of the ways is that, to access the element of the array you use the index.
For example, if you want a value for $motorcycle[3] to change to "ducati".
<?php
$motorcycle[1] = "suzuki";
$motorcycle[2] = "ktm";
$motorcycle[3] = "honda";
$motorcycle[3] = "ducati";
?>
Result:
ducati
If after that you want to add a new element "kawasaki" and that he needs to go to the end of the array. This you can do with shortcut for adding a new element, and that is the statement $motorcycle[].
Example 2:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
$motorcycle[2] = "ducati";
$motorcycle[] = "kawasaki";
?>
To display the content you should go through array.
Example 3:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
$motorcycle[2] = "ducati";
$motorcycle[] = "kawasaki";
for ($index = 0; $index < count($motorcycle); $index++) {
echo $motorcycle[$index], "<br />";
}
?>
Result:
suzuki
ktm
ducati
kawasaki
If you want you can copy whole array in the 2nd array.
Example 4:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
$motorcycle[2] = "ducati";
$motorcycle[] = "kawasaki";
$italyProduce = $motorcycle;
echo $italyProduce[2];
?>
Result:
ducati
Primer: ako zelite da vrednost za $motor[3] promenite na "ducati".
<?php
$motor[1] = "suzuki";
$motor[2] = "ktm";
$motor[3] = "honda";
$motor[3] = "ducati";
?>
Rezultat:
ducati
Ako posle toga zelite da dodate novi element "kawasaki" i da on treba da ide na kraj niza. Ovo mozete da uradite pomocu precice za dodavanje novog elementa, a to je iskaz $motor[].
Primer 2:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
$motor[2] = "ducati";
$motor[] = "kawasaki";
?>
Da prikazete sadrzaj treba da prodjete kroz niz.
Primer 3:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
$motor[2] = "ducati";
$motor[] = "kawasaki";
for ($indeks = 0; $indeks < count($motor); $indeks++) {
echo $motor[$indeks], "<br />";
}
?>
Rezultat:
suzuki
ktm
ducati
kawasaki
Ako zelite mozete i da ceo niz kopirate u drugi niz.
Primer 4:
<?php
$motor[0] = "suzuki";
$motor[1] = "ktm";
$motor[2] = "honda";
$motor[2] = "ducati";
$motor[] = "kawasaki";
$italijaProizvodi = $motor;
echo $italijaProizvodi[2];
?>
Rezultat:
ducati
If you have already made array, there is a possibility to change the value in the array. One of the ways is that, to access the element of the array you use the index.
For example, if you want a value for $motorcycle[3] to change to "ducati".
<?php
$motorcycle[1] = "suzuki";
$motorcycle[2] = "ktm";
$motorcycle[3] = "honda";
$motorcycle[3] = "ducati";
?>
Result:
ducati
If after that you want to add a new element "kawasaki" and that he needs to go to the end of the array. This you can do with shortcut for adding a new element, and that is the statement $motorcycle[].
Example 2:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
$motorcycle[2] = "ducati";
$motorcycle[] = "kawasaki";
?>
To display the content you should go through array.
Example 3:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
$motorcycle[2] = "ducati";
$motorcycle[] = "kawasaki";
for ($index = 0; $index < count($motorcycle); $index++) {
echo $motorcycle[$index], "<br />";
}
?>
Result:
suzuki
ktm
ducati
kawasaki
If you want you can copy whole array in the 2nd array.
Example 4:
<?php
$motorcycle[0] = "suzuki";
$motorcycle[1] = "ktm";
$motorcycle[2] = "honda";
$motorcycle[2] = "ducati";
$motorcycle[] = "kawasaki";
$italyProduce = $motorcycle;
echo $italyProduce[2];
?>
Result:
ducati
Subscribe to:
Posts (Atom)





