HOWTO - Web

Prohlížeč Telnet :-)
$ telnet www.server.cz 80
GET index.html HTTP/1.0
Podmínky v HTML
<!--[if IE ]>
<div style="text-align: center;">
<a href="http://firefox.czilla.cz/">
<img alt="Mozilla Firefox: Objevte znovu web"
	title="Mozilla Firefox: Objevte znovu web"
	style="border:none; width:468px; height:60px;"
	src="http://firefox.czilla.cz/img/p/cz-ff-468x60-w-objevte.png" />
</a>
</div>
<![endif]-->
http://firefox.czilla.cz/propagace/
Prototyp XHTML 1.0 stránky
<?xml version="1.0" encoding="iso-8859-2"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="CS">

<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-2" />
<meta http-equiv="content-language" content="cs" />

<title>Index</title>

<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="author" content="all: Michal Turek; WOQ (zavináč) seznam.cz" />
<meta name="copyright" content="Copyright (c) 2006 Michal Turek" />
<meta name="robots" content="all, follow" />
<meta name="resource-type" content="document" />

<style type="text/css" media="all">@import "style.css";</style>
<style type="text/css" media="print">@import "print.css";</style>
<link href="img/p_ico.png" rel="shortcut icon" type="image/x-icon" />
</head>

<body>

<!--[if IE ]>
<div style="text-align: center">
<a href="http://firefox.czilla.cz/"><img alt="Mozilla Firefox: Objevte znovu web" title="Mozilla Firefox: Objevte znovu web" style="border:none; width:468px; height:60px;" src="http://firefox.czilla.cz/img/p/cz-ff-468x60-w-objevte.png" /></a>
</div>
<![endif]-->

</body>
</html>
PHP: Datum a čas
// YYYY-MM-DD HH-MM-SS
$date = date('Y-m-d H:i:s');
PHP: Výpis pole
print_r($pole);

echo '<pre>';
print_r($_SERVER);
echo '</pre>';
PHP: Rychlý výpis MySQL tabulky
function mysql_print_query($query)
{
	$result = mysql_query($query)
		OR die('<div class="warn">Error in MySQL query.</div>');

	if(mysql_num_rows($result) > 0)
	{
		$num_columns = mysql_num_fields($result);

		echo "<table>\n<tr>\n";
		for($i = 0; $i < $num_columns; $i++)
			echo '<th>'.mysql_field_name($result, $i)."</th>";
		echo "</tr>\n\n";

		while($row = mysql_fetch_array($result, MYSQL_NUM))
		{
			echo "<tr>";
			for($i = 0; $i < $num_columns; $i++)
				echo "<td>{$row[$i]}</td>";
			echo "</tr>\n";
		}

		echo "</table>\n\n";
	}
	else
	{
		echo "<p>Dotaz vrátil prázdný výsledek.</p>";
	}

	mysql_free_result($result);
}


function mysql_get_val($query)
{
	$result = mysql_query($query) OR die('<div class="warn">Error in MySQL query.</div>');
	$row = mysql_fetch_array($result, MYSQL_NUM);
	return $row[0];
}
PHP: Prototyp MySQL dotazu
// Jeden řádek
$query = "SELECT count(*) FROM tabulka";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

// Více řádků
$query = "SELECT * FROM tabulka";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{

}
CSS: margin
element { margin: top right bottom left; }
Přesměrování
<?php
header("HTTP/1.1 301 Moved Permanently");
Header('Location: http://www.stranka.cz/');
exit();

// Sám na sebe
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}");
exit();

// Na jinou stránku se stejným umístěním
header("Location: http://{$_SERVER['HTTP_HOST']}".dirname($_SERVER['PHP_SELF']).'/login.php');
exit();
?>
PHP
include $_SERVER['DOCUMENT_ROOT'].'/inc.php';

php.ini
error_reporting = E_ALL | E_STRICT
CSS pseudotřídy
:hover
:before
:after
:focused	označení tabulátorem, fokus prvku ve formuláři
:link		nenavštívený odkaz
:active		klik na odkaz, stisknuté tlačítko
:visited	navštívený odkaz
:first-child	první prvek
:first-line	první řádek
:first-letter	první znak
CSS: Následující element
/* První odstavec po nadpisu */
h1 + p { ... }
CSS: Více stylů pro jeden element
<div style="první_styl druhý_styl">text</div>
CSS: Vertikální zarovnání obrázku na řádku
img { vertical-align: middle; }
CSS: Obecný selektor
* { padding: 0px; margin: 0px; }
Zarovnání formulářových prvků
input, select { vertical-align: middle; }
label { width: 120px; float: left; display: block; }

<label for="jmeno">Jméno:</label> <input id="jméno" />
Promazání spamů z fóra
# Víc než tři odkazy a určité stáří příspěvku
DELETE FROM `vzkazy` WHERE text REGEXP '(.*http://){3,}' AND cas >= 1136941129
Zvýraznění elementů s title atributem
<span title="Nějaký popisek k textu">text</span>

span[title] { border-bottom: 1px dashed yellow; }
CSS selectors
Pattern Meaning
* Matches any element.
E Matches any E element (i.e., an element of type E).
E F Matches any F element that is a descendant of an E element.
E > F Matches any F element that is a child of an element E.
E:first-child Matches element E when E is the first child of its parent.
E:link
E:visited
Matches element E if E is the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited).
E:active
E:hover
E:focus
Matches E during certain user actions.
E:lang(c) Matches element of type E if it is in (human) language c (the document language specifies how language is determined).
E + F Matches any F element immediately preceded by an element E.
E[foo] Matches any E element with the "foo" attribute set (whatever the value).
E[foo="warning"] Matches any E element whose "foo" attribute value is exactly equal to "warning".
E[foo~="warning"] Matches any E element whose "foo" attribute value is a list of space-separated values, one of which is exactly equal to "warning".
E[lang|="en"] Matches any E element whose "lang" attribute has a hyphen-separated list of values beginning (from the left) with "en".
DIV.warning HTML only. The same as DIV[class~="warning"].
E#myid Matches any E element ID equal to "myid".
http://www.w3.org/TR/CSS2/selector.html
Předmět emailu, kódování znaků
$clearsubject = "něco ěščřžýáíé";
$encodedsubject = base64_encode($clearsubject);
$subject = "=?iso-8859-2?B?$encodedsubject?=";

http://www.abclinuxu.cz/poradna/programovani/show/109707
Sitemap generátor
http://www.xml-sitemaps.com/
Konverze webové stránky do PDF
http://web2pdfconvert.com/
Šablona na emaily
// $replaces = array('search' => 'replacement', ...);
function sendEmail($from, $to, $subject, $pathTemplate, $replaces = array())
{
	$headers  = "Return-Path: $from\n";
	$headers .= "From: $from\n";
	$headers .= "Reply-To: $from\n";
	$headers .= "Content-Type: text/plain; charset=utf-8\n";
	$headers .= "Content-Transfer-Encoding: 8bit\n";

	$subject64 = '=?utf-8?B?'.base64_encode($subject).'?=';

	$message = file_get_contents($pathTemplate) or die("Email template does not exist: $pathBody");

	foreach ($replaces as $search => $replacement) {
		$message = str_replace($search, $replacement, $message);
	}

	// DEBUG
	// echo str_replace("\n", "<br />", "<hr />To: $to\nSubject: $subject\n$headers\n$message<hr />");

	mail($to, $subject64, $message, $headers) or die("Email sending failed: $to");
}
Copyright © 2001-2011 Michal Turek <WOQ (zavináč) seznam.cz>
Valid XHTML 1.0 Strict, Valid CSS