1 Built-in Functions
[ Basic Functions ]
1.1 Variables in PHP
Scope / Range
<?php
$THISNAME = "Global";
myfunc();
function myfunc () {
$THISNAME = "Local";
echo "Hi, $THISNAME!\n";
}
?>
// Output will be: Hi, Local!
Arrays
$arr = array(0 => 'Hello', 1 => 'World');
echo "$arr[0]\n";
echo "$arr[1]\n";
See also:
2 Installation
-
RedHat.com/documentation/rhl9/rhl-ig-x86-de-9/... - Reference
RedHat Linux Installation
europe.redhat.com/documentation/rhl9/rhl-ig-x86-de-9/ch-guimode.php3
-
mavetju.org/unix/favicon.php - Reference
How to create favicon-icons? Put a favorite icon instead of the Browser's icon. On Unix:
giftopnm favicon.gif [CHR_PIPE] ppmtowinicon -output favicon.ico
Then, within head section:
(LINK REL="SHORTCUT ICON" HREF="/favicon.ico")
mavetju.org/unix/favicon.php
-
LAMPS.efactory.de/lamps-2-0... - CInternet:Webmaster Reference
LAMPS Tutorial. Kompilieren, Installieren und
Konfigurieren eines LAMPS Servers. Apache 2.0, Mod_Perl,
PHP, Mod_SSL, MySQL, PostgreSQL und PDFLib in wenigen
Schritten und anhand von Beispielen
lamps.efactory.de/lamps-2-0.shtml
2.1 Pear
# pear list
Installed packages:
===================
Package Version State
Archive_Tar 1.1 stable
Console_Getopt 1.2 stable
DB 1.7.6 stable
HTML_Template_IT 1.1 stable
HTTP 1.3.5 stable
Mail 1.1.4 stable
Net_SMTP 1.2.6 stable
Net_Socket 1.0.6 stable
Net_UserAgent_Detect 2.0.1 stable
PEAR 1.3.5 stable
XML_Parser 1.2.6 stable
XML_RPC 1.4.0 stable
-
PEAR.PHP.net/packages.php - Reference Software
Contents of PEAR. Authentication, Encryption, Web Services, XML etc.
pear.php.net/packages.php
3 Reference
3.1 File Handling
// write a file
$FH = fopen("zz_trash_out.txt", "w");
fwrite($FH, "Hi, World\n");
fwrite($FH, "Foo bar\n");
fclose($FH);
<?php
read_file('zz_trash_out.txt');
function read_file ( $filename, $return_max_lines=0, $callback_func=null, $do_rtrim=true, $buffer_size=1024 ) {
$FH = fopen( $filename, 'rb' );
while(1) {
$line = rtrim(fgets($FH, $buffer_size));
if (feof($FH)) { break; }
print "==> \"$line\"\n";
}
fclose($FH);
}
?>
php.benscom.com/manual/de/function.fopen.php↑
3.2 cURL
PHP >= 4.0.2
www.php.net/manual/de/ref.curl.php↑
See also:
4 Graphics, Charts
www.phplot.com/↑
5 XML RPC
Client
<?
include("xmlrpc_utils.php");
$request = array(
'method' => "greeting",
'args' => array(
"mode" => "yourmode" ,
"lookup" => "AdminProfile" ,
"source" => "mysource" ,
"cn" => 'mycn'
) ,
'host' => 'localhost', 'uri' => '/xmlrpc/server.php', 'port' => 80
);
$result = xu_rpc_http_concise($request);
var_dump($result);
?>
Server
<?php
include("xmlrpc_utils.php");
// ensure extension is loaded.
xu_load_extension();
/*
$request_xml = <<< END
<?xml version="1.0"?>
<methodCall>
<methodName>greeting</methodName>
<params>
<param>
<value><string>Dan</string></value>
</param>
</params>
</methodCall>
END;
*/
/* Get the client's request from the post data.... */
$request_xml = $HTTP_RAW_POST_DATA;
if(!$request_xml) {
$request_xml = $HTTP_GET_VARS[xml];
}
if(!$request_xml) {
echo "<h1>No XML input found!</h1>";
}
else {
$xmlrpc_server = xmlrpc_server_create();
// register methods
if(!xmlrpc_server_register_method($xmlrpc_server, "greeting", "greeting_func")) {
die("<h2>method registration failed.</h2>");
}
// parse xml and call method
echo xmlrpc_server_call_method(
$xmlrpc_server, $request_xml, $response,
array(output_type => "xml", version => "auto")
);
// free server resources
$success = xmlrpc_server_destroy($xmlrpc_server);
}
function greeting_func($method_name, $params, $app_data) {
$name = $params[0];
return array("hello $name. How are you today?!");
}
?>
6 SOAP
See also:
6.1 Autogenerate PHP Code from WSDL
File: soap-autogen.php
Download → files/soap autogen php.txt
<?php
require_once 'SOAP/Client.php';
$wsdl = new SOAP_WSDL(
'http://www.webservicex.net/globalweather.asmx?WSDL');
$proxy = $wsdl->generateProxyCode('', 'StationInfo');
echo '<pre>';
echo htmlspecialchars($proxy);
echo '</pre>';
?>
→ files/soap weather class php.txt
Requirements
Download SOAP Package from pear.php.net.
There are dependencies of that package:
pear.php.net/package/Net_URL↑,
pear.php.net/package/HTTP_Request↑,
pear.php.net/package/Net_Socket↑
You might have to uninstall following packages first since Net_Socket has to have at least
version 1.0.6
# pear uninstall Net_Socket Net_POP3 Net_SMTP
then
# pear install Net_Socket
# pear install HTTP_Request
# pear install SOAP-0.9.4
See also:
6.2 Get Weather information with SOAP and WSDL
Client
<?php
require_once 'SOAP/Client.php';
require_once 'soap-weather-class.php';
$weather = new StationInfo();
$CityName = 'Zurich';
$CountryName = 'Switzerland';
echo $weather->GetWeather($CityName, $CountryName);
?>
The related Class file
<?php
class StationInfo extends SOAP_Client
{
function StationInfo($path = 'http://www.webservicex.net/globalweather.asmx')
{
$this->SOAP_Client($path, 0);
}
function &GetWeather($CityName, $CountryName)
{
$GetWeather =& new SOAP_Value('{http://www.webserviceX.NET}GetWeather', false, $v = array('CityName' => $CityName, 'CountryName' => $CountryName));
$result = $this->call('GetWeather',
$v = array('GetWeather' => $GetWeather),
array('namespace' => 'http://www.webserviceX.NET',
'soapaction' => 'http://www.webserviceX.NET/GetWeather',
'style' => 'document',
'use' => 'literal'));
return $result;
}
function &GetCitiesByCountry($CountryName)
{
$GetCitiesByCountry =& new SOAP_Value('{http://www.webserviceX.NET}GetCitiesByCountry', false, $v = array('CountryName' => $CountryName));
$result = $this->call('GetCitiesByCountry',
$v = array('GetCitiesByCountry' => $GetCitiesByCountry),
array('namespace' => 'http://www.webserviceX.NET',
'soapaction' => 'http://www.webserviceX.NET/GetCitiesByCountry',
'style' => 'document',
'use' => 'literal'));
return $result;
}
}
?>
XML Output
<?xml version="1.0" encoding="utf-16"?>
<CurrentWeather>
<Location>Zurich-Kloten, Switzerland (LSZH) 47-29N 008-32E 432M</Location>
<Time>Mar 16, 2006 - 07:20 AM EST / 2006.03.16 1220 UTC</Time>
<Wind> from the ENE (060 degrees) at 10 MPH (9 KT):0</Wind>
<Visibility> 3 mile(s):0</Visibility>
<SkyConditions> mostly cloudy</SkyConditions>
<Temperature> 35 F (2 C)</Temperature>
<Wind>Windchill: 26 F (-3 C):1</Wind>
<DewPoint> 26 F (-3 C)</DewPoint>
<RelativeHumidity> 69%</RelativeHumidity>
<Pressure> 30.06 in. Hg (1018 hPa)</Pressure>
<Status>Success</Status>
</CurrentWeather>
6.3 SOAP Error Handling
SOAP Client with Error Handling
<?php
require_once 'SOAP/Client.php';
require_once 'soap-client-class.php';
$service = new StationInfo();
$id = 1000;
$first = 'Hans';
$last = 'Muster';
$result = $service->doFuncFoo($id, $first, $last);
if (PEAR::isError($result)) {
$fault = $result->getFault();
echo $fault->{'faultstring'};
}
else {
var_dump($result);
}
?>
7 Helper Code
7.1 MySQL Database
<html>
<?
mysql_connect("localhost", "user", "pass") or die ("Could not connect to db");
mysql_select_db("reto") or die ("Could not select db");
$result = mysql_query("SELECT * FROM foo") or die ("Error");
if ($result) {
while ($row = mysql_fetch_array($result)) {
print $row["firstname"];
print " ";
print $row["lastname"];
print "<br>\n";
}
mysql_free_result($result);
}
?>
</html>
› See MySQL User Management for how to create a MySQL account.
› Create a table - create SQL online
-
php.net/manual/de/ref.mysql.php - Reference
MySQL Funktionen
ch2.php.net/manual/de/ref.mysql.php
-
LAMPS.efactory.de/lamps-2-0... - CInternet:Webmaster Reference
LAMPS Tutorial. Kompilieren, Installieren und
Konfigurieren eines LAMPS Servers. Apache 2.0, Mod_Perl,
PHP, Mod_SSL, MySQL, PostgreSQL und PDFLib in wenigen
Schritten und anhand von Beispielen
lamps.efactory.de/lamps-2-0.shtml
-
JuicyStudio.com/tutorials.html - CInternet:Webmaster Reference
Web Development, Extensible Markup Language (XML) Tutorial, Active Server Pages (ASP) Tutorial, Extensible HyperText Markup Language (XHTML), Wireless Markup Language (WML), JavaScript Tutorial, Java Tutorial, PHP Tutorial, MySQL Tutorial, Perl Tutorial, Cascading Style Sheets Tutorial, Flash Tutorial, HTML Web Safe Colour Codes, Browser Compatibility Chart
juicystudio.com/tutorials.html
-
PHP - CInternet
PHP ist eine Server-seitige Skriptsprache, um komfortabel und performant auf relationale Datenbanken zuzugreifen, z.B. mySql.
php.net
8 Cryptographic Functions
Crypt
9 LDAP
Ldap
10 Socket Connection
<?
$ret = socket_raw_connect("localhost", 80, 30, "GET / HTTP/1.0");
echo "$ret\n";
function socket_raw_connect ($server, $port, $timeout,$request)
{
if (!is_numeric($port) or !is_numeric($timeout)) {return false;}
$socket = fsockopen($server, $port, $errno, $errstr, $timeout);
if (!$socket) {
echo "Could not connect to $server:$port\n";
return "";
}
fputs($socket, "$request\n\n");
$ret = '';
while (!feof($socket))
{
$ret .= fgets($socket, 4096);
}
return $ret;
fclose($socket);
}
?>
11 Links
-
PHP.net/manual/de/print/control-structures.php
Kontrollstrukturen
-
Funktionen: Referenzen zurückgeben
-
Datum und Zeit
-
Tokens
- PHP-Center.de/en-html-manual/install.configure.html
Complete list of configure options
- Cryptography
http://ch.php.net/mcrypt
An interface to the mcrypt library, which supports a wide variety of block algorithms such as DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB, CFB and ECB cipher modes
12 Alphabetical Index
C - D - E - F - G - L - M - P - S - V - W
- PEAR Autogenerate PHP Code from WSDL
- Weather Get Weather information with SOAP and WSDL
- WSDL Autogenerate PHP Code from WSDL