last bunch of <programlisting>/CDATA changes

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@62977 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Hartmut Holzgraefe 2001-11-21 23:05:19 +00:00
parent 3eef86a4f8
commit 65a93a86a8
30 changed files with 1117 additions and 579 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.23 $ -->
<!-- $Revision: 1.24 $ -->
<reference id="ref.oracle">
<title>Oracle functions</title>
<titleabbrev>Oracle</titleabbrev>
@ -43,15 +43,17 @@
values if available.
<informalexample>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
ora_parse($curs, "declare tmp INTEGER; begin tmp := :in; :out := tmp; :x := 7.77; end;");
ora_bind($curs, "result", ":x", $len, 2);
ora_bind($curs, "input", ":in", 5, 1);
ora_bind($curs, "output", ":out", 5, 2);
$input = 765;
ora_exec($curs);
echo "Result: $result&lt;BR>Out: $output&lt;BR>In: $input";
echo "Result: $result<BR>Out: $output<BR>In: $input";
?>
]]>
</programlisting>
</informalexample>
</para>
@ -414,12 +416,14 @@ remove the unique restriction or do not insert the key
<example>
<title>Oracle fetch into array</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
array($results);
ora_fetch_into($cursor, &amp;$results);
ora_fetch_into($cursor, &$results);
echo $results[0];
echo $results[1];
?>
]]>
</programlisting>
</example>
Note that you need to fetch the array by reference.
@ -511,7 +515,7 @@ echo $results[1];
<informalexample>
<programlisting role="php">
$conn = Ora_Logon("user<emphasis>@TNSNAME</emphasis>", "pass");
</programlisting>
</programlisting>
</informalexample>
</para>
<para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.18 $ -->
<!-- $Revision: 1.19 $ -->
<reference id="ref.outcontrol">
<title>Output Control Functions</title>
<titleabbrev>Output Control</titleabbrev>
@ -19,7 +19,8 @@
<example>
<title>Output Control example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
ob_start();
echo "Hello\n";
@ -28,7 +29,8 @@ setcookie ("cookiename", "cookiedata");
ob_end_flush();
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -154,7 +156,8 @@ ob_end_flush();
<example>
<title>User defined callback function example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
function callback($buffer) {
@ -165,30 +168,33 @@ function callback($buffer) {
ob_start("callback");
?&gt;
?>
&lt;html&gt;
&lt;body&gt;
&lt;p&gt;It's like comparing apples to oranges.
&lt;/body&gt;
&lt;/html&gt;
<html>
<body>
<p>It's like comparing apples to oranges.
</body>
</html>
&lt;?php
<?php
ob_end_flush();
?&gt;
?>
]]>
</programlisting>
</example>
<para>
Would produce:
<informalexample>
<programlisting role="php">
&lt;html&gt;
&lt;body&gt;
&lt;p&gt;It's like comparing oranges to oranges.
&lt;/body&gt;
&lt;/html&gt;
<![CDATA[
<html>
<body>
<p>It's like comparing oranges to oranges.
</body>
</html>
]]>
</programlisting>
</informalexample>
</para>
@ -284,16 +290,18 @@ ob_end_flush();
<example>
<title><function>ob_gzhandler</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
ob_start("ob_gzhandler");
?>
&lt;html&gt;
&lt;body&gt;
&lt;p&gt;This should be a compressed page.
&lt;/html&gt;
&lt;/body&gt;
<html>
<body>
<p>This should be a compressed page.
</html>
<body>
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.12 $ -->
<!-- $Revision: 1.13 $ -->
<reference id="ref.ovrimos">
<title>Ovrimos SQL functions</title>
<titleabbrev>OvrimosSQL</titleabbrev>
@ -22,7 +22,8 @@
Connect to Ovrimos SQL Server and select from a system table
</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$conn = ovrimos_connect ("server.domain.com", "8001", "admin", "password");
if ($conn != 0) {
echo ("Connection ok!");
@ -34,7 +35,8 @@ if ($conn != 0) {
}
ovrimos_close($conn);
}
?&gt;
?>
]]>
</programlisting>
</example>
This will just connect to SQL Server.
@ -72,7 +74,8 @@ if ($conn != 0) {
<example>
<title><function>ovrimos_connect</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$conn = ovrimos_connect ("server.domain.com", "8001", "admin", "password");
if ($conn != 0) {
echo "Connection ok!";
@ -84,7 +87,8 @@ if ($conn != 0) {
}
ovrimos_close($conn);
}
?&gt;
?>
]]>
</programlisting>
</example>
The above example will connect to the database and print out the
@ -172,7 +176,8 @@ if ($conn != 0) {
<example>
<title>Connect to Ovrimos SQL Server and prepare a statement</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$conn=ovrimos_connect ("db_host", "8001", "admin", "password");
if ($conn!=0) {
echo "Connection ok!";
@ -192,7 +197,8 @@ if ($conn!=0) {
}
ovrimos_close($conn);
}
?&gt;
?>
]]>
</programlisting>
</example>
This will connect to Ovrimos SQL Server, prepare a statement and
@ -326,17 +332,18 @@ if ($conn!=0) {
<example>
<title>A fetch into example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$conn=ovrimos_connect ("neptune", "8001", "admin", "password");
if ($conn!=0) {
echo "Connection ok!";
$res=ovrimos_exec ($conn,"select table_id, table_name from sys.tables");
if ($res != 0) {
echo "Statement ok!";
if (ovrimos_fetch_into ($res, &amp;$row)) {
if (ovrimos_fetch_into ($res, &$row)) {
list ($table_id, $table_name) = $row;
echo "table_id=".$table_id.", table_name=".$table_name."\n";
if (ovrimos_fetch_into ($res, &amp;$row)) {
if (ovrimos_fetch_into ($res, &$row)) {
list ($table_id, $table_name) = $row;
echo "table_id=".$table_id.", table_name=".$table_name."\n";
} else {
@ -349,7 +356,8 @@ if ($conn!=0) {
}
ovrimos_close($conn);
}
?&gt;
?>
]]>
</programlisting>
</example>
This example will fetch a row.
@ -389,7 +397,8 @@ if ($conn!=0) {
<example>
<title>A fetch row example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$conn = ovrimos_connect ("remote.host", "8001", "admin", "password");
if ($conn != 0) {
echo "Connection ok!";
@ -414,7 +423,8 @@ if ($conn != 0) {
}
ovrimos_close($conn);
}
?&gt;
?>
]]>
</programlisting>
</example>
This will fetch a row and print the result.
@ -478,7 +488,8 @@ if ($conn != 0) {
<example>
<title>Prepare a statement, execute, and view the result</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$conn = ovrimos_connect ("db_host", "8001", "admin", "password");
if ($conn != 0) {
echo "Connection ok!";
@ -498,7 +509,8 @@ if ($conn != 0) {
}
ovrimos_close($conn);
}
?&gt;
?>
]]>
</programlisting>
</example>
This will execute an SQL statement and print the result in an
@ -508,7 +520,8 @@ if ($conn != 0) {
<example>
<title>Ovrimos_result_all with meta-information</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$conn = ovrimos_connect ("db_host", "8001", "admin", "password");
if ($conn != 0) {
echo "Connection ok!";
@ -518,7 +531,7 @@ if ($conn != 0) {
echo "Statement ok! cursor=".ovrimos_cursor ($res)."\n";
$colnb = ovrimos_num_fields ($res);
echo "Output columns=".$colnb."\n";
for ($i=1; $i&lt;=$colnb; $i++) {
for ($i=1; $i <= $colnb; $i++) {
$name = ovrimos_field_name ($res, $i);
$type = ovrimos_field_type ($res, $i);
$len = ovrimos_field_len ($res, $i);
@ -529,7 +542,8 @@ if ($conn != 0) {
}
ovrimos_close($conn);
}
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -537,7 +551,8 @@ if ($conn != 0) {
<example>
<title>ovrimos_result_all example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$conn = ovrimos_connect ("db_host", "8001", "admin", "password");
if ($conn != 0) {
echo "Connection ok!";
@ -549,7 +564,8 @@ if ($conn != 0) {
}
ovrimos_close($conn);
}
?&gt;
?>
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.6 $ -->
<!-- $Revision: 1.7 $ -->
<reference id="ref.pcntl">
<title>Process Control Functions</title>
<titleabbrev>PCNTL</titleabbrev>
@ -114,7 +114,8 @@
<example>
<title>Process Control Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$pid = pcntl_fork();
if ($pid == -1) {
@ -160,6 +161,7 @@ function sig_handler($signo) {
?>
]]>
</programlisting>
</example>
</sect1>
@ -195,7 +197,8 @@ function sig_handler($signo) {
<example>
<title><function>pcntl_fork</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$pid = pcntl_fork();
if ($pid == -1) {
@ -206,7 +209,8 @@ if ($pid == -1) {
// we are the child
}
?&gt;
?>
]]>
</programlisting>
</example>
<para>
@ -246,7 +250,8 @@ if ($pid == -1) {
<example>
<title><function>pcntl_signal</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
// signal handler function
function sig_handler($signo) {
@ -283,7 +288,8 @@ posix_kill(posix_getpid(), SIGUSR1);
print "Done\n"
?&gt;
?>
]]>
</programlisting>
</example>
<para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.62 $ -->
<!-- $Revision: 1.63 $ -->
<reference id="ref.pcre">
<title>Regular Expression Functions (Perl-Compatible)</title>
<titleabbrev>PCRE</titleabbrev>
@ -23,7 +23,7 @@
<example>
<title>Examples of valid patterns</title>
<itemizedlist>
<listitem><simpara>/&lt;\/\w+>/</simpara></listitem>
<listitem><simpara>/&lt;\/\w+&gt;/</simpara></listitem>
<listitem><simpara>|(\d{3})-\d+|Sm</simpara></listitem>
<listitem><simpara>/^(?i)php[34]/</simpara></listitem>
<listitem><simpara>{^\s+(\s+)?$}</simpara></listitem>
@ -102,17 +102,20 @@
<example>
<title>Find the string of text "php"</title>
<programlisting role="php">
<![CDATA[
// the "i" after the pattern delimiter indicates a case-insensitive search
if (preg_match ("/php/i", "PHP is the web scripting language of choice.")) {
print "A match was found.";
} else {
print "A match was not found.";
}
]]>
</programlisting>
</example>
<example>
<title>find the word "web"</title>
<programlisting role="php">
<![CDATA[
// the \b in the pattern indicates a word boundary, so only the distinct
// word "web" is matched, and not a word partial like "webbing" or "cobweb"
if (preg_match ("/\bweb\b/i", "PHP is the web scripting language of choice.")) {
@ -125,11 +128,13 @@ if (preg_match ("/\bweb\b/i", "PHP is the website scripting language of choice."
} else {
print "A match was not found.";
}
]]>
</programlisting>
</example>
<example>
<title>Getting the domain name out of a URL</title>
<programlisting role="php">
<![CDATA[
// get host name from URL
preg_match("/^(http:\/\/)?([^\/]+)/i",
"http://www.php.net/index.html", $matches);
@ -137,12 +142,17 @@ $host = $matches[2];
// get last two segments of host name
preg_match("/[^\.\/]+\.[^\.\/]+$/",$host,$matches);
echo "domain name is: ".$matches[0]."\n";
]]>
</programlisting>
</example>
<para>
This example will produce:
<programlisting>
<screen>
<![CDATA[
domain name is: php.net
</programlisting>
]]>
</screen>
</para>
</example>
See also <function>preg_match_all</function>,
<function>preg_replace</function>, and
<function>preg_split</function>.
@ -190,22 +200,26 @@ domain name is: php.net
the first parenthesized subpattern, and so on.
<informalexample>
<programlisting role="php">
preg_match_all ("|&lt;[^>]+>(.*)&lt;/[^>]+>|U",
"&lt;b>example: &lt;/b>&lt;div align=left>this is a test&lt;/div>",
<![CDATA[
preg_match_all ("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a test</div>",
$out, PREG_PATTERN_ORDER);
print $out[0][0].", ".$out[0][1]."\n";
print $out[1][0].", ".$out[1][1]."\n"
</programlisting>
</informalexample>
This example will produce:
<informalexample>
<programlisting>
&lt;b>example: &lt;/b>, &lt;div align=left>this is a test&lt;/div>
]]>
</programlisting>
<para>
This example will produce:
<screen>
<![CDATA[
<b>example: </b>, <div align=left>this is a test</div>
example: , this is a test
</programlisting>
</informalexample>
So, $out[0] contains array of strings that matched full pattern,
and $out[1] contains array of strings enclosed by tags.
]]>
</screen>
So, $out[0] contains array of strings that matched full pattern,
and $out[1] contains array of strings enclosed by tags.
</para>
</informalexample>
</para>
</listitem>
</varlistentry>
@ -218,18 +232,22 @@ example: , this is a test
and so on.
<informalexample>
<programlisting role="php">
preg_match_all ("|&lt;[^>]+>(.*)&lt;/[^>]+>|U",
"&lt;b>example: &lt;/b>&lt;div align=left>this is a test&lt;/div>",
<![CDATA[
preg_match_all ("|<;[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a test</div>",
$out, PREG_SET_ORDER);
print $out[0][0].", ".$out[0][1]."\n";
print $out[1][0].", ".$out[1][1]."\n"
print $out[1][0].", ".$out[1][1]."\n";
]]>
</programlisting>
</informalexample>
This example will produce:
<informalexample>
<programlisting role="php">
&lt;b>example: &lt;/b>, example:
&lt;div align=left>this is a test&lt;/div>, this is a test
<![CDATA[
<b>example: </b>, example:
<div align=left>this is a test</div>, this is a test
]]>
</programlisting>
</informalexample>
In this case, $matches[0] is the first set of matches, and
@ -252,8 +270,10 @@ print $out[1][0].", ".$out[1][1]."\n"
<example>
<title>Getting all phone numbers out of some text.</title>
<programlisting role="php">
<![CDATA[
preg_match_all ("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
"Call 555-1212 or 1-800-555-1212", $phones);
]]>
</programlisting>
</example>
</para>
@ -261,33 +281,37 @@ preg_match_all ("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
<example>
<title>Find matching HTML tags (greedy)</title>
<programlisting role="php">
<![CDATA[
// The \\2 is an example of backreferencing. This tells pcre that
// it must match the second set of parentheses in the regular expression
// itself, which would be the ([\w]+) in this case. The extra backslash is
// required because the string is in double quotes.
$html = "&lt;b&gt;bold text&lt;/b&gt;&lt;a href=howdy.html&gt;click me&lt;/a&gt;
$html = "<b>bold text</b><a href=howdy.html>click me</a>
preg_match_all ("/(&lt;([\w]+)[^&gt;]*&gt;)(.*)(&lt;\/\\2&gt;)/", $html, $matches);
preg_match_all ("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $html, $matches);
for ($i=0; $i&lt; count($matches[0]); $i++) {
for ($i=0; $i< count($matches[0]); $i++) {
echo "matched: ".$matches[0][$i]."\n";
echo "part 1: ".$matches[1][$i]."\n";
echo "part 2: ".$matches[3][$i]."\n";
echo "part 3: ".$matches[4][$i]."\n\n";
}
]]>
</programlisting>
</example>
This example will produce:
<programlisting>
matched: &lt;b&gt;bold text&lt;/b&gt;
part 1: &lt;b&gt;
<![CDATA[
matched: <b>bold text</b>
part 1: <b>
part 2: bold text
part 3: &lt;/b&gt;
part 3: </b>
matched: &lt;a href=howdy.html&gt;click me&lt;/a&gt;
part 1: &lt;a href=howdy.html&gt;
matched: <a href=howdy.html>click me</a>
part 1: <a href=howdy.html>
part 2: click me
part 3: &lt;/a&gt;
part 3: </a>
]]>
</programlisting>
</para>
<simpara>
@ -378,37 +402,44 @@ part 3: &lt;/a&gt;
<example>
<title>Replacing several values</title>
<programlisting>
<![CDATA[
$patterns = array ("/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/",
"/^\s*{(\w+)}\s*=/");
$replace = array ("\\3/\\4/\\1\\2", "$\\1 =");
print preg_replace ($patterns, $replace, "{startDate} = 1999-5-27");
]]>
</programlisting>
</example>
This example will produce:
<programlisting>
<![CDATA[
$startDate = 5/27/1999
]]>
</programlisting>
<example>
<title>Using /e modifier</title>
<programlisting role="php">
preg_replace ("/(&lt;\/?)(\w+)([^>]*>)/e",
<![CDATA[
preg_replace ("/(<\/?)(\w+)([^>]*>)/e",
"'\\1'.strtoupper('\\2').'\\3'",
$html_body);
]]>
</programlisting>
<para>
This would capitalize all HTML tags in the input text.
This would capitalize all HTML tags in the input text.
</para>
</example>
<example>
<title>Convert HTML to text</title>
<programlisting role="php">
<![CDATA[
// $document should contain an HTML document.
// This will remove HTML tags, javascript sections
// and white space. It will also convert some
// common HTML entities to their text equivalent.
$search = array ("'&lt;script[^&gt;]*?&gt;.*?&lt;/script&gt;'si", // Strip out javascript
"'&lt;[\/\!]*?[^&lt;&gt;]*?&gt;'si", // Strip out html tags
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip out html tags
"'([\r\n])[\s]+'", // Strip out white space
"'&amp;(quot|#34);'i", // Replace html entities
"'&amp;(amp|#38);'i",
@ -426,8 +457,8 @@ $replace = array ("",
"\\1",
"\"",
"&amp;",
"&lt;",
"&gt;",
"<",
">",
" ",
chr(161),
chr(162),
@ -436,6 +467,7 @@ $replace = array ("",
"chr(\\1)");
$text = preg_replace ($search, $replace, $document);
]]>
</programlisting>
</example>
</para>
@ -552,9 +584,11 @@ $text = preg_replace ($search, $replace, $document);
<example>
<title><function>preg_split</function> example : Get the parts of a search string.</title>
<programlisting role="php">
<![CDATA[
// split the phrase by any number of commas or space characters,
// which include " ", \r, \t, \n and \f
$keywords = preg_split ("/[\s,]+/", "hypertext language, programming");
]]>
</programlisting>
</example>
</para>
@ -562,9 +596,11 @@ $keywords = preg_split ("/[\s,]+/", "hypertext language, programming");
<example>
<title>Splitting a string into component characters.</title>
<programlisting role="php">
<![CDATA[
$str = 'string';
$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
print_r($chars);
]]>
</programlisting>
</example>
</para>
@ -611,21 +647,23 @@ print_r($chars);
used delimiter.</para>
<para>
The special regular expression characters are:
<screen>. \\ + * ? [ ^ ] $ ( ) { } = ! &lt; > | :</screen>
<screen>. \\ + * ? [ ^ ] $ ( ) { } = ! < > | :</screen>
</para>
<para>
<example>
<title></title>
<programlisting role="php">
<![CDATA[
$keywords = "$40 for a g3/400";
$keywords = preg_quote ($keywords, "/");
echo $keywords; // returns \$40 for a g3\/400
]]>
</programlisting>
</example>
<example>
<title>Italicizing a word within some text</title>
<programlisting role="php">
<![CDATA[
// In this example, preg_quote($word) is used to keep the
// asterisks from having special meaning to the regular
// expression.
@ -633,8 +671,9 @@ echo $keywords; // returns \$40 for a g3\/400
$textbody = "This book is *very* difficult to find.";
$word = "*very*";
$textbody = preg_replace ("/".preg_quote($word)."/",
"&lt;i&gt;".$word."&lt;/i&gt;",
"<i>".$word."</i>",
$textbody);
]]>
</programlisting>
</example>
</para>
@ -673,9 +712,11 @@ $textbody = preg_replace ("/".preg_quote($word)."/",
<example>
<title><function>preg_grep</function> example</title>
<programlisting role="php">
<![CDATA[
// return all array elements
// containing floating point numbers
$fl_array = preg_grep ("/^(\d+)?\.\d+$/", $array);
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.69 $ -->
<!-- $Revision: 1.70 $ -->
<reference id="ref.pdf">
<title>PDF functions </title>
<titleabbrev>PDF</titleabbrev>
@ -256,7 +256,8 @@
<example>
<title>Creating a PDF document with PDFlib</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
$pdf = pdf_new();
pdf_open_file($pdf, "test.pdf");
pdf_set_info($pdf, "Author", "Uwe Steinmann");
@ -274,21 +275,24 @@ pdf_stroke($pdf);
pdf_end_page($pdf);
pdf_close($pdf);
pdf_delete($pdf);
echo "&lt;A HREF=getpdf.php>finished&lt;/A>";
echo "<A HREF=getpdf.php>finished</A>";
?>
]]>
</programlisting>
<simpara>
The script <filename>getpdf.php</filename> just returns the pdf document.
</simpara>
<informalexample>
<programlisting>
&lt;?php
<![CDATA[
<?php
$len = filesize($filename);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=foo.pdf");
readfile($filename);
?>
]]>
</programlisting>
</informalexample>
</example>
@ -305,7 +309,8 @@ readfile($filename);
<example>
<title>pdfclock example from PDFlib distribution</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
$radius = 200;
$margin = 20;
$pagecount = 10;
@ -335,7 +340,7 @@ while($pagecount-- > 0) {
/* minute strokes */
pdf_setlinewidth($pdf, 2.0);
for ($alpha = 0; $alpha &lt; 360; $alpha += 6) {
for ($alpha = 0; $alpha < 360; $alpha += 6) {
pdf_rotate($pdf, 6.0);
pdf_moveto($pdf, $radius, 0.0);
pdf_lineto($pdf, $radius-$margin/3, 0.0);
@ -347,7 +352,7 @@ while($pagecount-- > 0) {
/* 5 minute strokes */
pdf_setlinewidth($pdf, 3.0);
for ($alpha = 0; $alpha &lt; 360; $alpha += 30) {
for ($alpha = 0; $alpha < 360; $alpha += 30) {
pdf_rotate($pdf, 30.0);
pdf_moveto($pdf, $radius, 0.0);
pdf_lineto($pdf, $radius-$margin, 0.0);
@ -410,6 +415,7 @@ print $buf;
pdf_delete($pdf);
?>
]]>
</programlisting>
</example>
</para>
@ -1187,14 +1193,16 @@ pdf_delete($pdf);
<example>
<title><function>pdf_findfont</function> example</title>
<programlisting role="php">
&lt;php
<![CDATA[
<?php
$font = pdf_findfont($pdf, "Times New Roman", "winansi", 1);
if ($font) {
pdf_setfont($pdf, $font, 10);
}
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -1572,7 +1580,8 @@ if ($font) {
<example>
<title>Creating a PDF document in memory</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$pdf = pdf_new();
@ -1593,6 +1602,7 @@ header("Content-length: " . strlen($data));
echo $data;
?>
]]>
</programlisting>
</example>
</para>
@ -1712,7 +1722,8 @@ echo $data;
<example>
<title>Including a memory image</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
$im = ImageCreate(100, 100);
$col = ImageColorAllocate($im, 80, 45, 190);
ImageFill($im, 10, 10, $col);
@ -1721,6 +1732,7 @@ ImageDestroy($im);
pdf_place_image($pdf, $pim, 100, 100, 1);
pdf_close_image($pdf, $pim);
?>
]]>
</programlisting>
</example></para>
<para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.9 $ -->
<!-- $Revision: 1.10 $ -->
<reference id="ref.pfpro">
<title>Verisign Payflow Pro functions</title>
<titleabbrev>Verisign Payflow Pro</titleabbrev>
@ -180,7 +180,8 @@
<example>
<title>Payflow Pro example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
pfpro_init();
@ -211,6 +212,7 @@ print_r($response);
pfpro_cleanup();
?>
]]>
</programlisting>
</example>
</refsect1>
@ -277,11 +279,12 @@ pfpro_cleanup();
<example>
<title>Payflow Pro raw example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
pfpro_init();
$response = pfpro_process("USER=mylogin&amp;PWD[5]=m&amp;ndy&amp;TRXTYPE=S&amp;TENDER=C&amp;AMT=1.50&amp;ACCT=4111111111111111&amp;EXPDATE=0904");
$response = pfpro_process("USER=mylogin&PWD[5]=m&ndy&TRXTYPE=S&TENDER=C&AMT=1.50&ACCT=4111111111111111&EXPDATE=0904");
if (!$response) {
die("Couldn't establish link to Verisign.\n");
@ -292,6 +295,7 @@ echo "Verisign raw response was ".$response;
pfpro_cleanup();
?>
]]>
</programlisting>
</example>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.47 $ -->
<!-- $Revision: 1.48 $ -->
<reference id="ref.pgsql">
<title>PostgreSQL functions</title>
<titleabbrev>PostgreSQL</titleabbrev>
@ -89,7 +89,8 @@
<example>
<title>Using Large Objects</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$database = pg_Connect ("dbname=jacarta");
pg_exec ($database, "begin");
$oid = pg_locreate ($database);
@ -100,6 +101,7 @@
pg_loclose ($handle);
pg_exec ($database, "commit");
?>
]]>
</programlisting>
</example>
</para>
@ -155,11 +157,13 @@
<example>
<title><function>pg_cmdtuples</function></title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$result = pg_exec ($conn, "INSERT INTO publisher VALUES ('Author')");
$cmdtuples = pg_cmdtuples ($result);
echo $cmdtuples . " &lt;- cmdtuples affected.";
?>
]]>
</programlisting>
</example>
</para>
@ -211,7 +215,8 @@ echo $cmdtuples . " &lt;- cmdtuples affected.";
<example>
<title>Using pg_connect arguments</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$dbconn = pg_Connect ("dbname=mary");
//connect to a database named "mary"
$dbconn2 = pg_Connect ("host=localhost port=5432 dbname=mary");
@ -219,6 +224,7 @@ $dbconn2 = pg_Connect ("host=localhost port=5432 dbname=mary");
$dbconn3 = pg_Connect ("host=sheep port=5432 dbname=mary user=lamb password=baaaa");
//connect to a database named "mary" on the host "sheep" with a username and password
?>
]]>
</programlisting>
</example>
The arguments available include <parameter>host</parameter>,
@ -409,7 +415,8 @@ $dbconn3 = pg_Connect ("host=sheep port=5432 dbname=mary user=lamb password=baaa
<example>
<title>PostgreSQL fetch array</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$conn = pg_pconnect ("dbname=publisher");
if (!$conn) {
echo "An error occured.\n";
@ -423,11 +430,12 @@ if (!$result) {
}
$arr = pg_fetch_array ($result, 0);
echo $arr[0] . " &lt;- array\n";
echo $arr[0] . " <- array\n";
$arr = pg_fetch_array ($result, 1);
echo $arr["author"] . " &lt;- array\n";
echo $arr["author"] . " <- array\n";
?>
]]>
</programlisting>
</example>
</refsect1>
@ -483,11 +491,12 @@ echo $arr["author"] . " &lt;- array\n";
<example>
<title>Postgres fetch object</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$database = "verlag";
$db_conn = pg_connect ("host=localhost port=5432 dbname=$database");
if (!$db_conn): ?>
&lt;H1>Failed connecting to postgres database &lt;?php echo $database ?>&lt;/H1> &lt;?php
<H1>Failed connecting to postgres database <?php echo $database ?></H1> <?php
exit;
endif;
@ -497,11 +506,11 @@ $row = 0; // postgres needs a row counter other dbs might not
while ($data = pg_fetch_object ($qu, $row)):
echo $data->autor." (";
echo $data->jahr ."): ";
echo $data->titel."&lt;BR>";
echo $data->titel."<BR>";
$row++;
endwhile; ?>
&lt;PRE>&lt;?php
<PRE><?php
$fields[] = Array ("autor", "Author");
$fields[] = Array ("jahr", " Year");
$fields[] = Array ("titel", " Title");
@ -516,10 +525,11 @@ while ($data = pg_fetch_object ($qu, $row)):
$row++;
endwhile;
echo "----------\n"; ?>
&lt;/PRE> &lt;?php
</PRE> <?php
pg_freeResult ($qu);
pg_close ($db_conn);
?>
]]>
</programlisting>
</example>
</para>
@ -557,7 +567,8 @@ pg_close ($db_conn);
<example>
<title>Postgres fetch row</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$conn = pg_pconnect ("dbname=publisher");
if (!$conn) {
echo "An error occured.\n";
@ -572,18 +583,19 @@ if (!$result) {
$num = pg_numrows($result);
for ($i=0; $i&lt;$num; $i++) {
for ($i=0; $i < $num; $i++) {
$r = pg_fetch_row($result, $i);
for ($j=0; $j&lt;count($r); $j++) {
echo "$r[$j]&amp;nbsp;";
for ($j=0; $j < count($r); $j++) {
echo "$r[$j]&nbsp;";
}
echo "&lt;BR>";
echo "<BR>";
}
?>
]]>
</programlisting>
</example>
</para>
@ -1203,7 +1215,8 @@ for ($i=0; $i&lt;$num; $i++) {
<example>
<title>High-speed insertion of data into a table</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$conn = pg_pconnect ("dbname=foo");
pg_exec($conn, "create table bar (a int4, b char(16), d float8)");
pg_exec($conn, "copy bar from stdin");
@ -1212,6 +1225,7 @@ for ($i=0; $i&lt;$num; $i++) {
pg_put_line($conn, "\\.\n");
pg_end_copy($conn);
?>
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.11 $ -->
<!-- $Revision: 1.12 $ -->
<reference id="ref.printer">
<title>Printer functions</title>
<titleabbrev>Printer</titleabbrev>
@ -41,8 +41,10 @@
<example>
<title><function>printer_open</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open("HP Deskjet 930c");
$handle = printer_open();
]]>
</programlisting>
</example>
</refsect1>
@ -71,9 +73,11 @@ $handle = printer_open();
<example>
<title><function>printer_abort</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_abort($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -103,8 +107,10 @@ printer_close($handle);
<example>
<title><function>printer_close</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -135,9 +141,11 @@ printer_close($handle);
<example>
<title><function>printer_write</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_write($handle, "Text to print");
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -219,8 +227,10 @@ printer_close($handle);
<example>
<title><function>printer_list</function> example</title>
<programlisting role="php">
<![CDATA[
/* detect locally shared printer */
var_dump( printer_list(PRINTER_ENUM_LOCAL | PRINTER_ENUM_SHARED) );
]]>
</programlisting>
</example>
</refsect1>
@ -448,10 +458,12 @@ var_dump( printer_list(PRINTER_ENUM_LOCAL | PRINTER_ENUM_SHARED) );
<example>
<title><function>printer_set_option</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_set_option($handle, PRINTER_SCALE, 75);
printer_set_option($handle, PRINTER_TEXT_ALIGN, PRINTER_TA_LEFT);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -495,9 +507,11 @@ printer_close($handle);
<example>
<title><function>printer_get_option</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
print printer_get_option($handle, PRINTER_DRIVERVERSION);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -525,6 +539,7 @@ printer_close($handle);
<example>
<title><function>printer_create_dc</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle);
printer_start_page($handle);
@ -546,6 +561,7 @@ printer_delete_dc($handle);
printer_endpage($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -599,6 +615,7 @@ printer_close($handle);
<example>
<title><function>printer_start_doc</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -606,6 +623,7 @@ printer_start_page($handle);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -803,6 +821,7 @@ printer_close($handle);
<function>printer_select_pen</function> example
</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -817,6 +836,7 @@ printer_delete_pen($pen);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -951,6 +971,7 @@ printer_close($handle);
<function>printer_select_brush</function> example
</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -975,6 +996,7 @@ printer_delete_pen($pen);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -1128,6 +1150,7 @@ printer_close($handle);
<function>printer_select_font</function> example
</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -1140,6 +1163,7 @@ printer_delete_font($font);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -1170,9 +1194,11 @@ printer_close($handle);
<function>printer_logical_fontheight</function> example
</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
print printer_logical_fontheight($handle, 72);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -1226,6 +1252,7 @@ printer_close($handle);
<title>
<function>printer_draw_roundrect</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -1244,6 +1271,7 @@ printer_delete_pen($pen);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -1290,6 +1318,7 @@ printer_close($handle);
<function>printer_draw_rectangle</function> example
</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -1308,6 +1337,7 @@ printer_delete_pen($pen);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -1352,6 +1382,7 @@ printer_close($handle);
<function>printer_draw_elipse</function> example
</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -1370,6 +1401,7 @@ printer_delete_pen($pen);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -1401,6 +1433,7 @@ printer_close($handle);
<example>
<title><function>printer_draw_text</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -1413,6 +1446,7 @@ printer_delete_font($font);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -1445,6 +1479,7 @@ printer_close($handle);
<example>
<title><function>printer_draw_line</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -1460,6 +1495,7 @@ printer_delete_pen($pen);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -1526,6 +1562,7 @@ printer_close($handle);
<example>
<title><function>printer_draw_chord</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -1544,6 +1581,7 @@ printer_delete_pen($pen);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -1609,6 +1647,7 @@ printer_close($handle);
<example>
<title><function>printer_draw_chord</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -1627,6 +1666,7 @@ printer_delete_pen($pen);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>
@ -1661,6 +1701,7 @@ printer_close($handle);
<example>
<title><function>printer_draw_bmp</function> example</title>
<programlisting role="php">
<![CDATA[
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
@ -1670,6 +1711,7 @@ printer_draw_bmp($handle, "c:\\image.bmp", 1, 1);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
]]>
</programlisting>
</example>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.20 $ -->
<!-- $Revision: 1.21 $ -->
<!-- pspell currently (2001-08-14) doesn't use resources -->
<reference id="ref.pspell">
@ -46,12 +46,14 @@
<example>
<title><function>pspell_add_to_personal</function></title>
<programlisting role="php">
<![CDATA[
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config ($pspell_config);
pspell_add_to_personal ($pspell_link, "Vlad");
pspell_save_wordlist ($pspell_link);
]]>
</programlisting>
</example>
</para>
@ -103,6 +105,7 @@ pspell_save_wordlist ($pspell_link);
<example>
<title><function>pspell_check</function></title>
<programlisting role="php">
<![CDATA[
$pspell_link = pspell_new ("en");
if (pspell_check ($pspell_link, "testt")) {
@ -110,6 +113,7 @@ if (pspell_check ($pspell_link, "testt")) {
} else {
echo "Sorry, wrong spelling";
}
]]>
</programlisting>
</example>
</para>
@ -138,6 +142,7 @@ if (pspell_check ($pspell_link, "testt")) {
<example>
<title><function>pspell_add_to_personal</function></title>
<programlisting role="php">
<![CDATA[
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config ($pspell_config);
@ -145,6 +150,7 @@ $pspell_link = pspell_new_config ($pspell_config);
pspell_add_to_personal ($pspell_link, "Vlad");
pspell_clear_session ($pspell_link);
pspell_save_wordlist ($pspell_link); //"Vlad" will not be saved
]]>
</programlisting>
</example>
</para>
@ -242,10 +248,12 @@ pspell_save_wordlist ($pspell_link); //"Vlad" will not be saved
<example>
<title><function>pspell_config_create</function></title>
<programlisting role="php">
<![CDATA[
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl ($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_personal ($pspell_config, "en");
]]>
</programlisting>
</example>
</para>
@ -276,10 +284,12 @@ $pspell_link = pspell_new_personal ($pspell_config, "en");
<example>
<title><function>pspell_config_ignore</function></title>
<programlisting role="php">
<![CDATA[
$pspell_config = pspell_config_create ("en");
pspell_config_ignore($pspell_config, 5);
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "abcd"); //will not result in an error
]]>
</programlisting>
</example>
</para>
@ -333,10 +343,12 @@ pspell_check($pspell_link, "abcd"); //will not result in an error
<example>
<title><function>pspell_config_mode</function></title>
<programlisting role="php">
<![CDATA[
$pspell_config = pspell_config_create ("en");
pspell_config_mode($pspell_config, PSPELL_FAST);
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "thecat");
]]>
</programlisting>
</example>
</para>
@ -372,10 +384,12 @@ pspell_check($pspell_link, "thecat");
<example>
<title><function>pspell_config_personal</function></title>
<programlisting role="php">
<![CDATA[
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config ($pspell_config);
pspell_check ($pspell_link, "thecat");
]]>
</programlisting>
</example>
</para>
@ -412,11 +426,13 @@ pspell_check ($pspell_link, "thecat");
<example>
<title><function>pspell_config_repl</function></title>
<programlisting role="php">
<![CDATA[
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl ($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_config ($pspell_config);
pspell_check ($pspell_link, "thecat");
]]>
</programlisting>
</example>
</para>
@ -451,10 +467,12 @@ pspell_check ($pspell_link, "thecat");
<example>
<title><function>pspell_config_runtogether</function></title>
<programlisting role="php">
<![CDATA[
$pspell_config = pspell_config_create ("en");
pspell_config_runtogether ($pspell_config, true);
$pspell_link = pspell_new_config ($pspell_config);
pspell_check ($pspell_link, "thecat");
]]>
</programlisting>
</example>
</para>
@ -597,8 +615,10 @@ pspell_check ($pspell_link, "thecat");
<example>
<title><function>pspell_new</function></title>
<programlisting role="php">
<![CDATA[
$pspell_link = pspell_new ("en", "", "", "",
(PSPELL_FAST|PSPELL_RUN_TOGETHER));
]]>
</programlisting>
</example>
</para>
@ -636,10 +656,12 @@ $pspell_link = pspell_new ("en", "", "", "",
<example>
<title><function>pspell_new_config</function></title>
<programlisting role="php">
<![CDATA[
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl ($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_config ($pspell_config);
]]>
</programlisting>
</example>
</para>
@ -767,8 +789,10 @@ $pspell_link = pspell_new_config ($pspell_config);
<example>
<title><function>pspell_new_personal</function></title>
<programlisting role="php">
<![CDATA[
$pspell_link = pspell_new_personal ("/var/dictionaries/custom.pws",
"en", "", "", "", PSPELL_FAST|PSPELL_RUN_TOGETHER));
]]>
</programlisting>
</example>
</para>
@ -801,12 +825,14 @@ $pspell_link = pspell_new_personal ("/var/dictionaries/custom.pws",
<example>
<title><function>pspell_add_to_personal</function></title>
<programlisting role="php">
<![CDATA[
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/tmp/dicts/newdict");
$pspell_link = pspell_new_config ($pspell_config);
pspell_add_to_personal ($pspell_link, "Vlad");
pspell_save_wordlist ($pspell_link);
]]>
</programlisting>
</example>
</para>
@ -845,6 +871,7 @@ pspell_save_wordlist ($pspell_link);
<example>
<title><function>pspell_store_replacement</function></title>
<programlisting role="php">
<![CDATA[
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl ($pspell_config, "/var/dictionaries/custom.repl");
@ -852,6 +879,7 @@ $pspell_link = pspell_new_config ($pspell_config);
pspell_store_replacement ($pspell_link, $misspelled, $correct);
pspell_save_wordlist ($pspell_link);
]]>
</programlisting>
</example>
</para>
@ -880,15 +908,17 @@ pspell_save_wordlist ($pspell_link);
<example>
<title><function>pspell_suggest</function></title>
<programlisting role="php">
<![CDATA[
$pspell_link = pspell_new ("en");
if (!pspell_check ($pspell_link, "testt")) {
$suggestions = pspell_suggest ($pspell_link, "testt");
foreach ($suggestions as $suggestion) {
echo "Possible spelling: $suggestion&lt;br>";
echo "Possible spelling: $suggestion<br>";
}
}
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.13 $ -->
<!-- $Revision: 1.14 $ -->
<reference id="ref.readline">
<title>GNU Readline</title>
<titleabbrev>Readline</titleabbrev>
@ -47,6 +47,7 @@
<example>
<title><function>readline</function></title>
<programlisting role="php">
<![CDATA[
//get 3 commands from user
for ($i=0; $i &lt; 3; $i++) {
$line = readline ("Command: ");
@ -58,6 +59,7 @@ print_r (readline_list_history());
//dump variables
print_r (readline_info());
]]>
</programlisting>
</example>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.15 $ -->
<!-- $Revision: 1.16 $ -->
<reference id="ref.recode">
<title>GNU Recode functions</title>
<titleabbrev>Recode</titleabbrev>
@ -48,7 +48,9 @@
<example>
<title>Basic <function>recode_string</function> example:</title>
<programlisting role="php">
print recode_string (&quot;us..flat&quot;, &quot;The following character has a diacritical mark: &amp;aacute;&quot;);
<![CDATA[
print recode_string ("us..flat", "The following character has a diacritical mark: &aacute;");
]]>
</programlisting>
</example>
</para>
@ -110,9 +112,11 @@ print recode_string (&quot;us..flat&quot;, &quot;The following character has a d
<example>
<title>Basic <function>recode_file</function> example</title>
<programlisting role="php">
<![CDATA[
$input = fopen ('input.txt', 'r');
$output = fopen ('output.txt', 'w');
recode_file (&quot;us..flat&quot;, $input, $output);
recode_file ("us..flat", $input, $output);
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.30 $ -->
<!-- $Revision: 1.31 $ -->
<reference id="ref.regex">
<title>Regular Expression Functions (POSIX Extended)</title>
<titleabbrev>Regexps</titleabbrev>
@ -55,16 +55,17 @@
<example>
<title>Regular Expression Examples</title>
<programlisting role="php">
ereg (&quot;abc&quot;, $string);
/* Returns true if &quot;abc&quot;
<![CDATA[
ereg ("abc", $string);
/* Returns true if"abc"
is found anywhere in $string. */
ereg (&quot;^abc&quot;, $string);
/* Returns true if &quot;abc&quot;
ereg ("^abc", $string);
/* Returns true if "abc";
is found at the beginning of $string. */
ereg ("abc$", $string);
/* Returns true if &quot;abc&quot;
/* Returns true if "abc"
is found at the end of $string. */
eregi ("(ozilla.[23]|MSIE.3)", $HTTP_USER_AGENT);
@ -75,15 +76,16 @@ ereg ("([[:alnum:]]+) ([[:alnum:]]+) ([[:alnum:]]+)", $string,$regs);
/* Places three space separated words
into $regs[1], $regs[2] and $regs[3]. */
$string = ereg_replace ("^", "&lt;br /&gt;", $string);
/* Put a &lt;br /&gt; tag at the beginning of $string. */
$string = ereg_replace ("^", "<br />", $string);
/* Put a <br /> tag at the beginning of $string. */
$string = ereg_replace ("$", "&lt;br /&gt;", $string);
/* Put a &lt;br /&gt; tag at the end of $string. */
$string = ereg_replace ("$", "<br />", $string);
/* Put a <br />; tag at the end of $string. */
$string = ereg_replace ("\n", "", $string);
/* Get rid of any newline
characters in $string. */
]]>
</programlisting>
</example>
</para>
@ -149,11 +151,13 @@ $string = ereg_replace ("\n", "", $string);
<example>
<title><function>ereg</function> Example</title>
<programlisting role="php">
<![CDATA[
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
echo "$regs[3].$regs[2].$regs[1]";
} else {
echo "Invalid date format: $date";
}
]]>
</programlisting>
</example>
</para>
@ -219,10 +223,12 @@ if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
<example>
<title><function>ereg_replace</function> Example</title>
<programlisting>
<![CDATA[
$string = "This is a test";
echo ereg_replace (" is", " was", $string);
echo ereg_replace ("( )is", "\\1was", $string);
echo ereg_replace ("(( )is)", "\\2was", $string);
]]>
</programlisting>
</example>
</para>
@ -235,7 +241,8 @@ echo ereg_replace ("(( )is)", "\\2was", $string);
<example>
<title><function>ereg_replace</function> Example</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
/* This will not work as expected. */
$num = 4;
$string = "This string has four words.";
@ -248,6 +255,7 @@ $string = "This string has four words.";
$string = ereg_replace('four', $num, $string);
echo $string; /* Output: 'This string has 4 words.' */
?>
]]>
</programlisting>
</example>
</para>
@ -255,8 +263,10 @@ echo $string; /* Output: 'This string has 4 words.' */
<example>
<title>Replace URLs with links</title>
<programlisting role="php">
$text = ereg_replace("[[:alpha:]]+://[^&lt;&gt;[:space:]]+[[:alnum:]/]",
"&lt;a href=\"\\0\"&gt;\\0&lt;/a&gt;", $text);
<![CDATA[
$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
"<a href=\"\\0\">\\0</a>", $text);
]]>
</programlisting>
</example>
</para>
@ -291,9 +301,11 @@ $text = ereg_replace("[[:alpha:]]+://[^&lt;&gt;[:space:]]+[[:alnum:]/]",
<example>
<title><function>eregi</function> example</title>
<programlisting role="php">
<![CDATA[
if (eregi("z", $string)) {
echo "'$string' contains a 'z' or 'Z'!";
}
]]>
</programlisting>
</example>
</para>
@ -372,7 +384,9 @@ if (eregi("z", $string)) {
<example>
<title><function>split</function> Example</title>
<programlisting role="php">
<![CDATA[
list($user,$pass,$uid,$gid,$extra)= split (":", $passwd_line, 5);
]]>
</programlisting>
</example>
</para>
@ -392,9 +406,11 @@ list($user,$pass,$uid,$gid,$extra)= split (":", $passwd_line, 5);
<example>
<title><function>split</function> Example</title>
<programlisting role="php">
<![CDATA[
$date = "04/30/1973"; // Delimiters may be slash, dot, or hyphen
list ($month, $day, $year) = split ('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year&lt;br&gt;\n";
echo "Month: $month; Day: $day; Year: $year<br>\n";
]]>
</programlisting>
</example>
</para>
@ -498,7 +514,9 @@ echo "Month: $month; Day: $day; Year: $year&lt;br&gt;\n";
<example>
<title><function>sql_regcase</function> Example</title>
<programlisting role="php">
<![CDATA[
echo sql_regcase ("Foo bar");
]]>
</programlisting>
</example>
prints <screen>[Ff][Oo][Oo] [Bb][Aa][Rr]</screen>.

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.17 $ -->
<!-- $Revision: 1.18 $ -->
<!-- Author: David Eriksson <david@2good.com> -->
<reference id="ref.satellite">
@ -38,13 +38,15 @@
<para>
<example>
<title>Sample IDL file</title>
<programlisting>
<programlisting role="idl">
<![CDATA[
interface MyInterface {
void SetInfo (string info);
string GetInfo();
attribute int value;
}
]]>
</programlisting>
</example>
</para>
@ -52,7 +54,8 @@ interface MyInterface {
<example>
<title>PHP code for accessing MyInterface</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$obj = new OrbitObject ($ior);
$obj->SetInfo ("A 2GooD object");
@ -63,6 +66,7 @@ $obj->value = 42;
echo $obj->value;
?>
]]>
</programlisting>
</example>
</para>
@ -93,10 +97,12 @@ echo $obj->value;
<para>
<example>
<title>Sample IDL file</title>
<programlisting>
<programlisting role="idl">
<![CDATA[
enum MyEnum {
a,b,c,d,e
};
]]>
</programlisting>
</example>
</para>
@ -104,13 +110,15 @@ enum MyEnum {
<example>
<title>PHP code for accessing MyEnum</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$enum = new OrbitEnum ("MyEnum");
echo $enum->a; /* write 0 */
echo $enum->c; /* write 2 */
echo $enum->e; /* write 4 */
?>
]]>
</programlisting>
</example>
</para>
@ -141,7 +149,8 @@ echo $enum->e; /* write 4 */
<para>
<example>
<title>Sample IDL file</title>
<programlisting>
<programlisting role="idl">
<![CDATA[
struct MyStruct {
short shortvalue;
string stringvalue;
@ -151,6 +160,7 @@ interface SomeInterface {
void SetValues (MyStruct values);
MyStruct GetValues();
}
]]>
</programlisting>
</example>
</para>
@ -158,7 +168,8 @@ interface SomeInterface {
<example>
<title>PHP code for accessing MyStruct</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$obj = new OrbitObject ($ior);
$initial_values = new OrbitStruct ("IDL:MyStruct:1.0");
@ -172,6 +183,7 @@ $values = $obj->GetValues();
echo $values->shortvalue;
echo $values->stringvalue;
?>
]]>
</programlisting>
</example>
</para>
@ -202,7 +214,8 @@ echo $values->stringvalue;
<para>
<example>
<title>Sample IDL file</title>
<programlisting>
<programlisting role="idl">
<![CDATA[
/* ++?????++ Out of Cheese Error. Redo From Start. */
exception OutOfCheeseError {
int parameter;
@ -211,6 +224,7 @@ exception OutOfCheeseError {
interface AnotherInterface {
void AskWhy() raises (OutOfCheeseError);
}
]]>
</programlisting>
</example>
</para>
@ -218,7 +232,8 @@ interface AnotherInterface {
<example>
<title>PHP code for handling CORBA exceptions</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$obj = new OrbitObject ($ior);
$obj->AskWhy();
@ -230,6 +245,7 @@ if (satellite_caught_exception()) {
}
}
?>
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.18 $ -->
<!-- $Revision: 1.19 $ -->
<reference id="ref.sesam">
<title>SESAM database functions</title>
<titleabbrev>SESAM</titleabbrev>
@ -63,7 +63,9 @@
Example:
<informalexample>
<programlisting role="apache">
<![CDATA[
php3_sesam_oml $.SYSLNK.SESAM-SQL.030
]]>
</programlisting>
</informalexample>
</para>
@ -78,16 +80,20 @@ php3_sesam_oml $.SYSLNK.SESAM-SQL.030
Example:
<informalexample>
<programlisting role="apache">
<![CDATA[
php3_sesam_configfile $SESAM.SESAM.CONF.AW
]]>
</programlisting>
</informalexample>
It will usually contain a configuration like (see SESAM
reference manual):
<informalexample>
<programlisting role="bs2000">
<![CDATA[
CNF=B
NAM=K
NOTYPE
]]>
</programlisting>
</informalexample>
</para>
@ -104,7 +110,9 @@ NOTYPE
Example:
<informalexample>
<programlisting role="apache">
<![CDATA[
php3_sesam_messagecatalog $.SYSMES.SESAM-SQL.030
]]>
</programlisting>
</informalexample>
</para>
@ -454,18 +462,22 @@ php3_sesam_messagecatalog $.SYSMES.SESAM-SQL.030
<example>
<title>Creating a "multiple field" column</title>
<programlisting role="sesam">
<![CDATA[
CREATE TABLE multi_field_test (
pkey CHAR(20) PRIMARY KEY,
multi(3) CHAR(12)
)
]]>
</programlisting>
</example>
and can be filled in using:
<example>
<title>Filling a "multiple field" column</title>
<programlisting role="sesam">
<![CDATA[
INSERT INTO multi_field_test (pkey, multi(2..3) )
VALUES ('Second', &lt;'first_val', 'second_val'&gt;)
VALUES ('Second', <'first_val', 'second_val'>)
]]>
</programlisting>
</example>
Note that (like in this case) leading empty sub-fields are
@ -540,10 +552,12 @@ INSERT INTO multi_field_test (pkey, multi(2..3) )
<example>
<title>Connect to a SESAM database</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
if (!sesam_connect ("mycatalog", "myschema", "otto")
die("Unable to connect to SESAM";
?&gt;
die("Unable to connect to SESAM");
?>
]]>
</programlisting>
</example>
</para>
@ -590,10 +604,12 @@ if (!sesam_connect ("mycatalog", "myschema", "otto")
<example>
<title>Closing a SESAM connection</title>
<programlisting role="php">
<![CDATA[
if (sesam_connect ("mycatalog", "myschema", "otto")) {
... some queries and stuff ...
sesam_disconnect();
}
]]>
</programlisting>
</example>
</para>
@ -709,10 +725,12 @@ if (sesam_connect ("mycatalog", "myschema", "otto")) {
<example>
<title>Setting SESAM transaction parameters</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
sesam_settransaction (SESAM_TXISOL_REPEATABLE_READ,
SESAM_TXREAD_READONLY);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -756,14 +774,16 @@ sesam_settransaction (SESAM_TXISOL_REPEATABLE_READ,
<example>
<title>Committing an update to the SESAM database</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
if (sesam_connect ("mycatalog", "myschema", "otto")) {
if (!sesam_execimm ("INSERT INTO mytable VALUES (*, 'Small Test', &lt;0, 8, 15&gt;)"))
if (!sesam_execimm ("INSERT INTO mytable VALUES (*, 'Small Test', <0, 8, 15>)"))
die("insert failed");
if (!sesam_commit())
die("commit failed");
}
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -805,15 +825,17 @@ if (sesam_connect ("mycatalog", "myschema", "otto")) {
<example>
<title>Discarding an update to the SESAM database</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
if (sesam_connect ("mycatalog", "myschema", "otto")) {
if (sesam_execimm ("INSERT INTO mytable VALUES (*, 'Small Test', &lt;0, 8, 15&gt;)")
&amp;&amp; sesam_execimm ("INSERT INTO othertable VALUES (*, 'Another Test', 1)"))
if (sesam_execimm ("INSERT INTO mytable VALUES (*, 'Small Test', <0, 8, 15>)")
&& sesam_execimm ("INSERT INTO othertable VALUES (*, 'Another Test', 1)"))
sesam_commit();
else
sesam_rollback();
}
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -863,12 +885,14 @@ if (sesam_connect ("mycatalog", "myschema", "otto")) {
<para>
<informalexample>
<programlisting role="php">
<![CDATA[
$stmt = "INSERT INTO mytable VALUES ('one', 'two')";
$result = sesam_execimm ($stmt);
$err = sesam_diagnostic();
print ("sqlstate = ".$err["sqlstate"]."\n".
"Affected rows = ".$err["rowcount"]." == ".
sesam_affected_rows($result)."\n");
]]>
</programlisting>
</informalexample>
See also: <function>sesam_query</function> and
@ -937,7 +961,8 @@ print ("sqlstate = ".$err["sqlstate"]."\n".
Show all rows of the "phone" table as a html table
</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
if (!sesam_connect ("phonedb", "demo", "otto"))
die ("cannot connect");
$result = sesam_query ("select * from phone");
@ -945,45 +970,46 @@ if (!$result) {
$err = sesam_diagnostic();
die ($err["errmsg"]);
}
echo "&lt;TABLE BORDER&gt;\n";
echo "<TABLE BORDER>\n";
// Add title header with column names above the result:
if ($cols = sesam_field_array ($result)) {
echo " &lt;TR&gt;&lt;TH COLSPAN=".$cols["count"]."&gt;Result:&lt;/TH&gt;&lt;/TR&gt;\n";
echo " &lt;TR&gt;\n";
for ($col = 0; $col &lt; $cols["count"]; ++$col) {
echo " <TR><TH COLSPAN=".$cols["count"].">Result:</TH></TR>\n";
echo " <TR>\n";
for ($col = 0; $col < $cols["count"]; ++$col) {
$colattr = $cols[$col];
/* Span the table head over SESAM's "Multiple Fields": */
if ($colattr["count"] &gt; 1) {
echo " &lt;TH COLSPAN=".$colattr["count"]."&gt;".$colattr["name"].
"(1..".$colattr["count"].")&lt;/TH&gt;\n";
if ($colattr["count"] > 1) {
echo " <TH COLSPAN=".$colattr["count"].">".$colattr["name"].
"(1..".$colattr["count"].")</TH>\n";
$col += $colattr["count"] - 1;
} else
echo " &lt;TH&gt;" . $colattr["name"] . "&lt;/TH&gt;\n";
echo " <TH>" . $colattr["name"] . "</TH>\n";
}
echo " &lt;/TR&gt;\n";
echo " </TR>\n";
}
do {
// Fetch the result in chunks of 100 rows max.
$ok = sesam_fetch_result ($result, 100);
for ($row=0; $row &lt; $ok["rows"]; ++$row) {
echo " &lt;TR&gt;\n";
for ($col = 0; $col &lt; $ok["cols"]; ++$col) {
for ($row=0; $row < $ok["rows"]; ++$row) {
echo " <TR>\n";
for ($col = 0; $col < $ok["cols"]; ++$col) {
if (isset($ok[$col][$row]))
echo " &lt;TD&gt;" . $ok[$col][$row] . "&lt;/TD&gt;\n";
echo " <TD>" . $ok[$col][$row] . "</TD>\n";
} else {
echo " &lt;TD&gt;-empty-&lt;/TD&gt;\n";
echo " <TD>-empty-</TD>\n";
}
}
echo " &lt;/TR&gt;\n";
echo " </TR>\n";
}
}
while ($ok["truncated"]) { // while there may be more data
echo "&lt;/TABLE&gt;\n";
echo "</TABLE>\n";
}
// free result id
sesam_free_result($result);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -1139,7 +1165,8 @@ sesam_free_result($result);
<example>
<title>Displaying SESAM error messages with error position</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
// Function which prints a formatted error message,
// displaying a pointer to the syntax error in the
// SQL statement
@ -1152,11 +1179,11 @@ function PrintReturncode ($exec_str) {
--$colspan;
if ($err["rowcount"] == 0)
--$colspan;
echo "&lt;TABLE BORDER&gt;\n";
echo "&lt;TR&gt;&lt;TH COLSPAN=".$colspan."&gt;&lt;FONT COLOR=red&gt;ERROR:&lt;/FONT&gt; ".
htmlspecialchars($err["errmsg"])."&lt;/TH&gt;&lt;/TR&gt;\n";
if ($err["errcol"] &gt;= 0) {
echo "&lt;TR&gt;&lt;TD COLSPAN=".$colspan."&gt;&lt;PRE&gt;\n";
echo "<TABLE BORDER>\n";
echo "<TR><TH COLSPAN=".$colspan."><FONT COLOR=red>ERROR:</FONT> ".
htmlspecialchars($err["errmsg"])."</TH></TR>\n";
if ($err["errcol"] >= 0) {
echo "<TR><TD COLSPAN=".$colspan."><PRE>\n";
$errstmt = $exec_str."\n";
for ($lin=0; $errstmt != ""; ++$lin) {
if ($lin != $err["errlin"]) { // $lin is less or greater than errlin
@ -1171,27 +1198,27 @@ function PrintReturncode ($exec_str) {
$i = "";
$line = substr ($errstmt, 0, strlen ($errstmt)-strlen($i)+1);
$errstmt = substr($i, 1);
for ($col=0; $col &lt; $err["errcol"]; ++$col)
for ($col=0; $col < $err["errcol"]; ++$col)
echo (substr($line, $col, 1) == "\t") ? "\t" : ".";
echo "&lt;FONT COLOR=RED&gt;&lt;BLINK&gt;\\&lt;/BLINK&gt;&lt;/FONT&gt;\n";
print "&lt;FONT COLOR=\"#880000\"&gt;".htmlspecialchars($line)."&lt;/FONT&gt;";
for ($col=0; $col &lt; $err["errcol"]; ++$col)
echo "<FONT COLOR=RED><BLINK>\\</BLINK></FONT>\n";
print "<FONT COLOR=\"#880000\">".htmlspecialchars($line)."</FONT>";
for ($col=0; $col < $err["errcol"]; ++$col)
echo (substr ($line, $col, 1) == "\t") ? "\t" : ".";
echo "&lt;FONT COLOR=RED&gt;&lt;BLINK&gt;/&lt;/BLINK&gt;&lt;/FONT&gt;\n";
echo "<FONT COLOR=RED><BLINK>/</BLINK></FONT>\n";
}
}
echo "&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;\n";
echo "</PRE></TD></TR>\n";
}
echo "&lt;TR&gt;\n";
echo " &lt;TD&gt;sqlstate=" . $err["sqlstate"] . "&lt;/TD&gt;\n";
echo "<TR>\n";
echo " <TD>sqlstate=" . $err["sqlstate"] . "</TD>\n";
if ($err["errlin"] != -1)
echo " &lt;TD&gt;errlin=" . $err["errlin"] . "&lt;/TD&gt;\n";
echo " <TD>errlin=" . $err["errlin"] . "</TD>\n";
if ($err["errcol"] != -1)
echo " &lt;TD&gt;errcol=" . $err["errcol"] . "&lt;/TD&gt;\n";
echo " <TD>errcol=" . $err["errcol"] . "</TD>\n";
if ($err["rowcount"] != 0)
echo " &lt;TD&gt;rowcount=" . $err["rowcount"] . "&lt;/TD&gt;\n";
echo "&lt;/TR&gt;\n";
echo "&lt;/TABLE&gt;\n";
echo " <TD>rowcount=" . $err["rowcount"] . "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
}
if (!sesam_connect ("mycatalog", "phoneno", "otto"))
@ -1202,7 +1229,8 @@ $stmt = "SELECT * FROM phone\n".
" ORDER BY FIRSTNAME";
if (!($result = sesam_query ($stmt)))
PrintReturncode ($stmt);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -1350,12 +1378,14 @@ if (!($result = sesam_query ($stmt)))
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
$result = sesam_execimm ("DELETE FROM PHONE WHERE LASTNAME = '".strtoupper ($name)."'");
if (!$result) {
... error ...
}
print sesam_affected_rows ($result).
" entries with last name ".$name." deleted.\n"
]]>
</programlisting>
</informalexample>
</refsect1>
@ -1380,8 +1410,10 @@ print sesam_affected_rows ($result).
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
if (!sesam_execimm ($stmt))
printf ("%s&lt;br&gt;\n", sesam_errormsg());
printf ("%s<br>\n", sesam_errormsg());
]]>
</programlisting>
</informalexample>
<para>
@ -1729,28 +1761,30 @@ if (!sesam_execimm ($stmt))
<example>
<title>SESAM fetch rows</title>
<programlisting role="php">
&lt;?php
$result = sesam_query (&quot;SELECT * FROM phone\n&quot;.
&quot; WHERE LASTNAME='&quot;.strtoupper($name).&quot;'\n&quot;.
&quot; ORDER BY FIRSTNAME&quot;, 1);
<![CDATA[
<?php
$result = sesam_query ("SELECT * FROM phone\n".
" WHERE LASTNAME='".strtoupper($name)."'\n".
" ORDER BY FIRSTNAME", 1);
if (!$result) {
... error ...
}
// print the table in backward order
print &quot;&lt;TABLE BORDER&gt;\n&quot;;
print "<TABLE BORDER>\n";
$row = sesam_fetch_row ($result, SESAM_SEEK_LAST);
while (is_array ($row)) {
print &quot; &lt;TR&gt;\n&quot;;
for ($col = 0; $col &lt; $row[&quot;count&quot;]; ++$col) {
print &quot; &lt;TD&gt;&quot;.htmlspecialchars ($row[$col]).&quot;&lt;/TD&gt;\n&quot;;
print " <TR>\n";
for ($col = 0; $col < $row["count"]; ++$col) {
print " <TD>".htmlspecialchars ($row[$col])."</TD>\n";
}
print &quot; &lt;/TR&gt;\n&quot;;
print " </TR>\n";
// use implied SESAM_SEEK_PRIOR
$row = sesam_fetch_row ($result);
}
print &quot;&lt;/TABLE&gt;\n&quot;;
print "</TABLE>\n";
sesam_free_result ($result);
?&gt;
?>
]]>
</programlisting>
</example>
<para>
@ -1816,8 +1850,11 @@ sesam_free_result ($result);
call <function>sesam_fetch_row</function> or make an alias for
the column.
<informalexample>
<programlisting>
SELECT TBL1.COL AS FOO, TBL2.COL AS BAR FROM TBL1, TBL2</programlisting>
<programlisting role="sesam">
<![CDATA[
SELECT TBL1.COL AS FOO, TBL2.COL AS BAR FROM TBL1, TBL2
]]>
</programlisting>
</informalexample>
</para>
<para>
@ -1831,7 +1868,9 @@ SELECT TBL1.COL AS FOO, TBL2.COL AS BAR FROM TBL1, TBL2</programlisting>
declared as:
<informalexample>
<programlisting role="sesam">
<![CDATA[
CREATE TABLE ... ( ... MULTI(3) INT )
]]>
</programlisting>
</informalexample>
the associative indices used for the individual "multiple field"
@ -1848,25 +1887,27 @@ CREATE TABLE ... ( ... MULTI(3) INT )
<example>
<title>SESAM fetch array</title>
<programlisting role="php">
&lt;?php
$result = sesam_query (&quot;SELECT * FROM phone\n&quot;.
&quot; WHERE LASTNAME='&quot;.strtoupper($name).&quot;'\n&quot;.
&quot; ORDER BY FIRSTNAME&quot;, 1);
<![CDATA[
<?php
$result = sesam_query ("SELECT * FROM phone\n".
" WHERE LASTNAME='".strtoupper($name)."'\n".
" ORDER BY FIRSTNAME", 1);
if (!$result) {
... error ...
}
// print the table:
print &quot;&lt;TABLE BORDER&gt;\n&quot;;
while (($row = sesam_fetch_array ($result)) &amp;&amp; count ($row) &gt; 0) {
print &quot; &lt;TR&gt;\n&quot;;
print &quot; &lt;TD&gt;&quot;.htmlspecialchars ($row[&quot;firstname&quot;]).&quot;&lt;/TD&gt;\n&quot;;
print &quot; &lt;TD&gt;&quot;.htmlspecialchars ($row[&quot;lastname&quot;]).&quot;&lt;/TD&gt;\n&quot;;
print &quot; &lt;TD&gt;&quot;.htmlspecialchars ($row[&quot;phoneno&quot;]).&quot;&lt;/TD&gt;\n&quot;;
print &quot; &lt;/TR&gt;\n&quot;;
print "<TABLE BORDER>\n";
while (($row = sesam_fetch_array ($result)) && count ($row) > 0) {
print " <TR>\n";
print " <TD>".htmlspecialchars ($row["firstname"])."</TD>\n";
print " <TD>".htmlspecialchars ($row["lastname"])."</TD>\n";
print " <TD>".htmlspecialchars ($row["phoneno"])."</TD>\n";
print " </TR>\n";
}
print &quot;&lt;/TABLE&gt;\n&quot;;
print "</TABLE>\n";
sesam_free_result ($result);
?&gt;
?>
]]>
</programlisting>
</example>
<para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.55 $ -->
<!-- $Revision: 1.56 $ -->
<reference id="ref.session">
<title>Session handling functions</title>
<titleabbrev>Sessions</titleabbrev>
@ -69,10 +69,12 @@
enabled
</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
session_register("count");
$HTTP_SESSION_VARS["count"]++;
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -89,10 +91,12 @@ $HTTP_SESSION_VARS["count"]++;
enabled
</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
session_register("count");
$count++;
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -142,19 +146,21 @@ $count++;
<example>
<title>Counting the number of hits of a single user</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
session_register ("count");
$count++;
?&gt;
?>
Hello visitor, you have seen this page &lt;?php echo $count; ?&gt; times.&lt;p&gt;
&lt;php?
# the &lt;?=SID?&gt; is necessary to preserve the session id
<?php
# the <?=SID?> is necessary to preserve the session id
# in the case that the user has disabled cookies
?&gt;
?>
To continue, &lt;A HREF="nextpage.php?&lt;?=SID?&gt;"&gt;click here&lt;/A&gt;
To continue, <A HREF="nextpage.php?<?=SID?>">click here</A>
]]>
</programlisting>
</example>
</para>
@ -421,14 +427,16 @@ To continue, &lt;A HREF="nextpage.php?&lt;?=SID?&gt;"&gt;click here&lt;/A&gt;
<example>
<title><function>session_name</function> examples</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
# set the session name to WebsiteID
$previous_name = session_name ("WebsiteID");
echo "The previous session name was $previous_name&lt;p&gt;";
?&gt;
echo "The previous session name was $previous_name<p>";
?>
]]>
</programlisting>
</example>
<note>
@ -846,8 +854,8 @@ echo "The previous session name was $previous_name&lt;p&gt;";
<function>session_set_save_handler</function> example
</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
function open ($save_path, $session_name) {
global $sess_save_path, $sess_session_name;
@ -906,7 +914,8 @@ session_start();
// proceed to use sessions normally
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -964,15 +973,17 @@ session_start();
<example>
<title><function>session_cache_limiter</function> examples</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
# set the cache limiter to 'private'
session_cache_limiter('private');
$cache_limiter = session_cache_limiter();
echo "The cache limiter is now set to $cache_limiter&lt;p&gt;";
?&gt;
echo "The cache limiter is now set to $cache_limiter<p>";
?>
]]>
</programlisting>
</example>
<note>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.9 $ -->
<!-- $Revision: 1.10 $ -->
<reference id="ref.shmop">
<title>Shared Memory Functions</title>
<titleabbrev>shmop</titleabbrev>
@ -24,7 +24,8 @@
<example>
<title>Shared Memory Operations Overview</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
// Create 100 byte shared memory block with system id if 0xff3
$shm_id = shmop_open(0xff3, "c", 0644, 100);
@ -55,7 +56,8 @@ if(!shmop_delete($shm_id)) {
}
shmop_close($shm_id);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -114,9 +116,11 @@ shmop_close($shm_id);
<example>
<title>Create a new shared memory block</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$shm_id = shmop_open(0x0fff, "c", 0644, 100);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -153,9 +157,11 @@ $shm_id = shmop_open(0x0fff, "c", 0644, 100);
<example>
<title>Reading shared memory block</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$shm_data = shmop_read($shm_id, 0, 50);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -194,9 +200,11 @@ $shm_data = shmop_read($shm_id, 0, 50);
<example>
<title>Writing to shared memory block</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$shm_bytes_written = shmop_write($shm_id, $my_string, 0);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -235,9 +243,11 @@ $shm_bytes_written = shmop_write($shm_id, $my_string, 0);
<example>
<title>Getting the size of the shared memory block</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$shm_size = shmop_size($shm_id);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -273,9 +283,11 @@ $shm_size = shmop_size($shm_id);
<example>
<title>Deleting shared memory block</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
shmop_delete($shm_id);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -310,9 +322,11 @@ shmop_delete($shm_id);
<example>
<title>Closing shared memory block</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
shmop_close($shm_id);
?&gt;
?>
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.16 $ -->
<!-- $Revision: 1.17 $ -->
<reference id="ref.snmp">
<title>SNMP functions</title>
<titleabbrev>SNMP</titleabbrev>
@ -16,8 +16,10 @@
#define line. It should look like this afterwards:</simpara>
<para>
<programlisting>
<programlisting role="c">
<![CDATA[
#define NO_ZEROLENGTH_COMMUNITY 1
]]>
</programlisting>
</para>
@ -60,7 +62,9 @@
<para>
<informalexample>
<programlisting role="php">
<![CDATA[
$syscontact = snmpget("127.0.0.1", "public", "system.SysContact.0");
]]>
</programlisting>
</informalexample>
</para>
@ -139,7 +143,9 @@ $syscontact = snmpget("127.0.0.1", "public", "system.SysContact.0");
<informalexample>
<programlisting role="php">
<![CDATA[
$a = snmpwalk("127.0.0.1", "public", "");
]]>
</programlisting>
</informalexample></para>
@ -150,9 +156,11 @@ $a = snmpwalk("127.0.0.1", "public", "");
<informalexample>
<programlisting role="php">
for ($i=0; $i&lt;count($a); $i++) {
<![CDATA[
for ($i=0; $i < count($a); $i++) {
echo $a[$i];
}
]]>
</programlisting>
</informalexample></para>
@ -204,7 +212,9 @@ for ($i=0; $i&lt;count($a); $i++) {
<informalexample>
<programlisting role="php">
<![CDATA[
$a = snmpwalkoid("127.0.0.1", "public", "");
]]>
</programlisting>
</informalexample></para>
@ -215,9 +225,11 @@ $a = snmpwalkoid("127.0.0.1", "public", "");
<informalexample>
<programlisting role="php">
<![CDATA[
for (reset($a); $i = key($a); next($a)) {
echo "$i: $a[$i]&lt;br>\n";
echo "$i: $a[$i]<br>\n";
}
]]>
</programlisting>
</informalexample></para>
@ -246,7 +258,9 @@ for (reset($a); $i = key($a); next($a)) {
<informalexample>
<programlisting role="php">
<![CDATA[
$quickprint = snmp_get_quick_print();
]]>
</programlisting>
</informalexample></para>
@ -297,12 +311,14 @@ $quickprint = snmp_get_quick_print();
<informalexample>
<programlisting role="php">
<![CDATA[
snmp_set_quick_print(0);
$a = snmpget("127.0.0.1", "public", ".1.3.6.1.2.1.2.2.1.9.1");
echo "$a&lt;BR>\n";
echo "$a<BR>\n";
snmp_set_quick_print(1);
$a = snmpget("127.0.0.1", "public", ".1.3.6.1.2.1.2.2.1.9.1");
echo "$a&lt;BR>\n";
echo "$a<BR>\n";
]]>
</programlisting>
</informalexample></para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.23 $ -->
<!-- $Revision: 1.24 $ -->
<reference id="ref.sockets">
<title>Socket functions</title>
<titleabbrev>Sockets</titleabbrev>
@ -48,7 +48,8 @@
side, and echoed back to you. To disconnect, enter 'quit'.
</para>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
error_reporting (E_ALL);
/* Allow the script to hang around waiting for connections. */
@ -57,27 +58,27 @@ set_time_limit (0);
$address = '192.168.1.53';
$port = 10000;
if (($sock = socket (AF_INET, SOCK_STREAM, 0)) &lt; 0) {
if (($sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
echo "socket() failed: reason: " . strerror ($sock) . "\n";
}
if (($ret = bind ($sock, $address, $port)) &lt; 0) {
if (($ret = bind ($sock, $address, $port)) < 0) {
echo "bind() failed: reason: " . strerror ($ret) . "\n";
}
if (($ret = listen ($sock, 5)) &lt; 0) {
if (($ret = listen ($sock, 5)) < 0) {
echo "listen() failed: reason: " . strerror ($ret) . "\n";
}
do {
if (($msgsock = accept_connect($sock)) &lt; 0) {
if (($msgsock = accept_connect($sock)) < 0) {
echo "accept_connect() failed: reason: " . strerror ($msgsock) . "\n";
break;
}
do {
$buf = '';
$ret = read ($msgsock, $buf, 2048);
if ($ret &lt; 0) {
if ($ret < 0) {
echo "read() failed: reason: " . strerror ($ret) . "\n";
break 2;
}
@ -98,6 +99,7 @@ do {
close ($sock);
?>
]]>
</programlisting>
</example>
</para>
@ -110,10 +112,11 @@ close ($sock);
and exits.
</para>
<programlisting>
&lt;?php
<![CDATA[
<?php
error_reporting (E_ALL);
echo "&lt;h2>TCP/IP Connection&lt;/h2>\n";
echo "<h2>TCP/IP Connection</h2>\n";
/* Get the port for the WWW service. */
$service_port = getservbyname ('www', 'tcp');
@ -123,7 +126,7 @@ $address = gethostbyname ('www.php.net');
/* Create a TCP/IP socket. */
$socket = socket (AF_INET, SOCK_STREAM, 0);
if ($socket &lt; 0) {
if ($socket < 0) {
echo "socket() failed: reason: " . strerror ($socket) . "\n";
} else {
"socket() successful: " . strerror ($socket) . "\n";
@ -131,7 +134,7 @@ if ($socket &lt; 0) {
echo "Attempting to connect to '$address' on port '$service_port'...";
$result = connect ($socket, $address, $service_port);
if ($result &lt; 0) {
if ($result < 0) {
echo "connect() failed.\nReason: ($result) " . strerror($result) . "\n";
} else {
echo "OK.\n";
@ -153,6 +156,7 @@ echo "Closing socket...";
close ($socket);
echo "OK.\n\n";
?>
]]>
</programlisting>
</example>
</para>
@ -546,7 +550,8 @@ echo "OK.\n\n";
<example>
<title><function>strerror</function> example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
if (($socket = socket (AF_INET, SOCK_STREAM, 0)) &lt; 0) {
echo "socket() failed: reason: " . strerror ($socket) . "\n";
}
@ -555,6 +560,7 @@ if (($ret = bind ($socket, '127.0.0.1', 80)) &lt; 0) {
echo "bind() failed: reason: " . strerror ($ret) . "\n";
}
?>
]]>
</programlisting>
<para>
The expected output from the above example (assuming the script

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.126 $ -->
<!-- $Revision: 1.127 $ -->
<reference id="ref.strings">
<title>String functions</title>
<titleabbrev>Strings</titleabbrev>
@ -54,7 +54,9 @@
<example>
<title><function>addcslashes</function> example</title>
<programlisting role="php">
<![CDATA[
$escaped = addcslashes($not_escaped, "\0..\37!@\177..\377");
]]>
</programlisting>
</example>
</para>
@ -64,9 +66,11 @@ $escaped = addcslashes($not_escaped, "\0..\37!@\177..\377");
characters that you set as the start and end of the range.
<informalexample>
<programlisting role="php">
<![CDATA[
echo addcslashes('foo[]', 'A..z');
// All upper and lower-case letters will be escaped
// ... but so will the [\]^_` and space characters.
]]>
</programlisting>
</informalexample>
Also, if the first character in a range has a lower ASCII value
@ -76,11 +80,13 @@ echo addcslashes('foo[]', 'A..z');
ASCII value for a character.
<informalexample>
<programlisting role="php">
<![CDATA[
echo addcslashes("zoo['.']", 'z..A');
/* output:
\zoo['\.']
*/
]]>
</programlisting>
</informalexample>
<note>
@ -192,11 +198,13 @@ echo addcslashes("zoo['.']", 'z..A');
<example>
<title><function>chr</function> example</title>
<programlisting role="php">
<![CDATA[
$str .= chr(27); /* add an escape character at the end of $str */
/* Often this is more useful */
$str = sprintf("The string ends in escape: %c", 27);
]]>
</programlisting>
</example>
</para>
@ -242,9 +250,11 @@ $str = sprintf("The string ends in escape: %c", 27);
<example>
<title><function>chunk_split</function> example</title>
<programlisting role="php">
<![CDATA[
# format $data using RFC 2045 semantics
$new_string = chunk_split(base64_encode($data));
]]>
</programlisting>
</example>
This function is significantly faster than
@ -523,7 +533,8 @@ $new_string = chunk_split(base64_encode($data));
<example>
<title><function>echo</function> examples</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
echo "Hello World";
echo "This spans
@ -554,6 +565,7 @@ echo $foo,$bar; // foobarbarbaz
($some_var) ? print('true'): print('false'); // print is a function
echo $some_var ? 'true': 'false'; // changing the statement around
?>
]]>
</programlisting>
</example>
</para>
@ -562,7 +574,9 @@ echo $some_var ? 'true': 'false'; // changing the statement around
can immediately follow the opening tag with an equals sign.
<informalexample>
<programlisting role="php">
I have &lt;?=$foo?> foo.
<![CDATA[
I have <?=$foo?> foo.
]]>
</programlisting>
</informalexample>
</para>
@ -617,8 +631,10 @@ I have &lt;?=$foo?> foo.
<example>
<title><function>explode</function> example</title>
<programlisting role="php">
<![CDATA[
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
]]>
</programlisting>
</example>
</para>
@ -679,9 +695,11 @@ $pieces = explode(" ", $pizza);
<example>
<title>Translation Table Example</title>
<programlisting role="php">
<![CDATA[
$trans = get_html_translation_table(HTML_ENTITIES);
$str = "Hallo &amp; &lt;Frau> &amp; Kr&auml;mer";
$str = "Hallo & <Frau> & Krämer";
$encoded = strtr($str, $trans);
]]>
</programlisting>
</example>
The <literal>$encoded</literal> variable will now contain: "Hallo
@ -694,8 +712,10 @@ $encoded = strtr($str, $trans);
the direction of the translation.
<informalexample>
<programlisting role="php">
<![CDATA[
$trans = array_flip($trans);
$original = strtr($str, $trans);
]]>
</programlisting>
</informalexample>
The content of <literal>$original</literal> would be: "Hallo &amp;
@ -739,9 +759,11 @@ $original = strtr($str, $trans);
<example>
<title>Meta Tags Example</title>
<programlisting role="html">
&lt;meta name="author" content="name">
&lt;meta name="tags" content="php3 documentation">
&lt;/head> &lt;!-- parsing stops here -->
<![CDATA[
<meta name="author" content="name">
<meta name="tags" content="php3 documentation">
</head> <!-- parsing stops here -->
]]>
</programlisting>
</example>
(pay attention to line endings - PHP uses a native function to
@ -947,7 +969,9 @@ $original = strtr($str, $trans);
<example>
<title><function>htmlspecialchars</function> example</title>
<programlisting role="php">
$new = htmlspecialchars("&lt;a href='test'&gt;Test&lt;/a&gt;", ENT_QUOTES);
<![CDATA[
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
]]>
</programlisting>
</example>
</para>
@ -989,7 +1013,9 @@ $new = htmlspecialchars("&lt;a href='test'&gt;Test&lt;/a&gt;", ENT_QUOTES);
<example>
<title><function>implode</function> example</title>
<programlisting role="php">
<![CDATA[
$colon_separated = implode(":", $array);
]]>
</programlisting>
</example>
</para>
@ -1334,11 +1360,12 @@ $colon_separated = implode(":", $array);
<example>
<title><function>localeconv</function> example</title>
<programlisting role="php">
<![CDATA[
setlocale(LC_ALL, "en_US");
$locale_info = localeconv();
echo "&lt;PRE&gt;\n";
echo "<PRE>\n";
echo "--------------------------------------------\n";
echo " Monetary information for current locale: \n";
echo "--------------------------------------------\n\n";
@ -1357,7 +1384,8 @@ echo "n_cs_precedes: {$locale_info["n_cs_precedes"]}\n";
echo "n_sep_by_space: {$locale_info["n_sep_by_space"]}\n";
echo "p_sign_posn: {$locale_info["p_sign_posn"]}\n";
echo "n_sign_posn: {$locale_info["n_sign_posn"]}\n";
echo "&lt;/PRE&gt;\n";
echo "</PRE>\n";
]]>
</programlisting>
</example>
<para>
@ -1596,9 +1624,11 @@ $clean = ltrim($binary,"\0x00..\0x1F");
<example>
<title><function>ord</function> example</title>
<programlisting role="php">
<![CDATA[
if (ord($str) == 10) {
echo "The first character of \$str is a line feed.\n";
}
]>
</programlisting>
</example>
</para>
@ -1639,11 +1669,13 @@ if (ord($str) == 10) {
<example>
<title>Using <function>parse_str</function></title>
<programlisting role="php">
$str = "first=value&amp;second[]=this+works&amp;second[]=another";
<![CDATA[
$str = "first=value&second[]=this+works&second[]=another";
parse_str($str);
echo $first; /* prints "value" */
echo $second[0]; /* prints "this works" */
echo $second[1]; /* prints "another" */
]]>
</programlisting>
</example>
</para>
@ -1890,12 +1922,14 @@ $clean = rtrim($binary,"\0x00..\0x1F");
<example>
<title><function>sscanf</function> Example</title>
<programlisting role="php">
<![CDATA[
// getting the serial number
$serial = sscanf("SN/2350001","SN/%d");
// and the date of manufacturing
$mandate = "January 01 2000";
list($month, $day, $year) = sscanf($mandate,"%s %d %d");
echo "Item $serial was manufactured on: $year-".substr($month,0,3)."-$day\n";
]]>
</programlisting>
</example>
If optional parameters are passed, the function will return the
@ -1904,13 +1938,15 @@ echo "Item $serial was manufactured on: $year-".substr($month,0,3)."-$day\n";
<example>
<title><function>sscanf</function> - using optional parameters</title>
<programlisting role="php">
<![CDATA[
// get author info and generate DocBook entry
$auth = "24\tLewis Carroll";
$n = sscanf($auth,"%d\t%s %s", &amp;$id, &amp;$first, &amp;$last);
echo "&lt;author id='$id'&gt;
&lt;firstname&gt;$first&lt;/firstname&gt;
&lt;surname&gt;$last&lt;/surname&gt;
&lt;/author&gt;\n";
echo "<author id='$id'>
<firstname>$first</firstname>
<surname>$last</surname>
</author>\n";
]]>
</programlisting>
</example>
</para>
@ -2062,12 +2098,14 @@ echo "&lt;author id='$id'&gt;
<example>
<title>Soundex Examples</title>
<programlisting role="php">
<![CDATA[
soundex("Euler") == soundex("Ellery") == 'E460';
soundex("Gauss") == soundex("Ghosh") == 'G200';
soundex("Hilbert") == soundex("Heilbronn") == 'H416';
soundex("Knuth") == soundex("Kant") == 'K530';
soundex("Lloyd") == soundex("Ladd") == 'L300';
soundex("Lukasiewicz") == soundex("Lissajous") == 'L222';
]]>
</programlisting>
</example>
</para>
@ -2201,8 +2239,10 @@ soundex("Lukasiewicz") == soundex("Lissajous") == 'L222';
<example>
<title>Argument swapping</title>
<programlisting role="php">
<![CDATA[
$format = "There are %d monkeys in the %s";
printf($format,$num,$location);
]]>
</programlisting>
</example>
This might output, "There are 5 monkeys in the tree". But
@ -2212,8 +2252,10 @@ printf($format,$num,$location);
<example>
<title>Argument swapping</title>
<programlisting role="php">
<![CDATA[
$format = "The %s contains %d monkeys";
printf($format,$num,$location);
]]>
</programlisting>
</example>
We now have a problem. The order of the placeholders in the
@ -2224,8 +2266,10 @@ printf($format,$num,$location);
<example>
<title>Argument swapping</title>
<programlisting role="php">
<![CDATA[
$format = "The %2\$s contains %1\$d monkeys";
printf($format,$num,$location);
]]>
</programlisting>
</example>
An added benefit here is that you can repeat the placeholders without
@ -2233,9 +2277,11 @@ printf($format,$num,$location);
<example>
<title>Argument swapping</title>
<programlisting role="php">
<![CDATA[
$format = "The %2\$s contains %1\$d monkeys.
That's a nice %2\$s full of %1\$d monkeys.";
printf($format, $num, $location);
]]>
</programlisting>
</example>
</para>
@ -2251,18 +2297,22 @@ printf($format, $num, $location);
<example>
<title><function>sprintf</function>: zero-padded integers</title>
<programlisting role="php">
<![CDATA[
$isodate = sprintf("%04d-%02d-%02d", $year, $month, $day);
]]>
</programlisting>
</example>
<example>
<title><function>sprintf</function>: formatting currency</title>
<programlisting role="php">
<![CDATA[
$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
// echo $money will output "123.1";
$formatted = sprintf("%01.2f", $money);
// echo $formatted will output "123.10"
]]>
</programlisting>
</example>
</para>
@ -2333,11 +2383,13 @@ $formatted = sprintf("%01.2f", $money);
<example>
<title><function>strcasecmp</function> example</title>
<programlisting role="php">
<![CDATA[
$var1 = "Hello";
$var2 = "hello";
if (!strcasecmp($var1, $var2)) {
echo '$var1 is equal to $var2 in a case-insensitive string comparison';
}
]]>
</programlisting>
</example>
</para>
@ -2511,7 +2563,9 @@ if (!strcasecmp($var1, $var2)) {
<example>
<title><function>strip_tags</function> example</title>
<programlisting role="php">
$string = strip_tags($string, '&lt;a&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;');
<![CDATA[
$string = strip_tags($string, '<a><b><i><u>');
]]>
</programlisting>
</example>
</para>
@ -2665,6 +2719,7 @@ $string = strip_tags($string, '&lt;a&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;');
below:
<informalexample>
<programlisting>
<![CDATA[
$arr1 = $arr2 = array("img12.png","img10.png","img2.png","img1.png");
echo "Standard string comparison\n";
usort($arr1,"strcmp");
@ -2672,29 +2727,32 @@ print_r($arr1);
echo "\nNatural order string comparison\n";
usort($arr2,"strnatcmp");
print_r($arr2);
]]>
</programlisting>
</informalexample>
The code above will generate the following output:
<informalexample>
<programlisting>
<screen>
<![CDATA[
Standard string comparison
Array
(
[0] =&gt; img1.png
[1] =&gt; img10.png
[2] =&gt; img12.png
[3] =&gt; img2.png
[0] => img1.png
[1] => img10.png
[2] => img12.png
[3] => img2.png
)
Natural order string comparison
Array
(
[0] =&gt; img1.png
[1] =&gt; img2.png
[2] =&gt; img10.png
[3] =&gt; img12.png
[0] => img1.png
[1] => img2.png
[2] => img10.png
[3] => img12.png
)
</programlisting>
]]>
</screen>
</informalexample>
For more information see: Martin Pool's <ulink
url="&url.strnatcmp;">Natural Order String Comparison</ulink>
@ -2853,10 +2911,12 @@ Array
<example>
<title><function>str_pad</function> example</title>
<programlisting role="php">
<![CDATA[
$input = "Alien";
print str_pad($input, 10); // produces "Alien "
print str_pad($input, 10, "-=", STR_PAD_LEFT); // produces "-=-=-Alien"
print str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___"
]]>
</programlisting>
</example>
</para>
@ -2899,6 +2959,7 @@ print str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___"
the difference:
<informalexample>
<programlisting role="php">
<![CDATA[
// in PHP 4.0b3 and newer:
$pos = strpos($mystring, "b");
if ($pos === false) { // note: three equal signs
@ -2907,9 +2968,10 @@ if ($pos === false) { // note: three equal signs
// in versions older than 4.0b3:
$pos = strpos($mystring, "b");
if (is_string($pos) &amp;&amp; !$pos) {
if (is_string($pos) && !$pos) {
// not found...
}
]]>
</programlisting>
</informalexample>
</para>
@ -2968,12 +3030,14 @@ if (is_string($pos) &amp;&amp; !$pos) {
<example>
<title><function>strrchr</function> example</title>
<programlisting role="php">
<![CDATA[
// get last directory in $PATH
$dir = substr(strrchr($PATH, ":"), 1);
// get everything after last newline
$text = "Line 1\nLine 2\nLine 3";
$last = substr(strrchr($text, 10), 1 );
]]>
</programlisting>
</example>
</para>
@ -3006,7 +3070,9 @@ $last = substr(strrchr($text, 10), 1 );
<example>
<title><function>str_repeat</function> example</title>
<programlisting role="php">
<![CDATA[
echo str_repeat("-=", 10);
]]>
</programlisting>
</example>
<para>
@ -3038,9 +3104,11 @@ echo str_repeat("-=", 10);
<example>
<title>Reversing a string with <function>strrev</function></title>
<programlisting role="php">
&lt;php
<![CDATA[
<php
echo strrev("Hello world!"); // outputs "!dlrow olleH"
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -3080,6 +3148,7 @@ echo strrev("Hello world!"); // outputs "!dlrow olleH"
the difference:
<informalexample>
<programlisting role="php">
<![CDATA[
// in PHP 4.0b3 and newer:
$pos = strrpos($mystring, "b");
if ($pos === false) { // note: three equal signs
@ -3088,9 +3157,10 @@ if ($pos === false) { // note: three equal signs
// in versions older than 4.0b3:
$pos = strrpos($mystring, "b");
if (is_string($pos) &amp;&amp; !$pos) {
if (is_string($pos) && !$pos) {
// not found...
}
]]>
</programlisting>
</informalexample>
</para>
@ -3133,7 +3203,9 @@ if (is_string($pos) &amp;&amp; !$pos) {
The line of code:
<informalexample>
<programlisting role="php">
<![CDATA[
$var = strspn("42 is the answer, what is the question ...", "1234567890");
]]>
</programlisting>
</informalexample>
will assign 2 to <varname>$var</varname>, because the string "42" will
@ -3182,9 +3254,11 @@ $var = strspn("42 is the answer, what is the question ...", "1234567890");
<example>
<title><function>strstr</function> example</title>
<programlisting role="php">
<![CDATA[
$email = 'sterling@designmultimedia.com';
$domain = strstr($email, '@');
print $domain; // prints @designmultimedia.com
]]>
</programlisting>
</example>
</para>
@ -3218,12 +3292,14 @@ print $domain; // prints @designmultimedia.com
<example>
<title><function>strtok</function> example</title>
<programlisting role="php">
<![CDATA[
$string = "This is an example string";
$tok = strtok($string," ");
while ($tok) {
echo "Word=$tok&lt;br>";
echo "Word=$tok<br>";
$tok = strtok(" ");
}
]]>
</programlisting>
</example>
</para>
@ -3273,9 +3349,11 @@ while ($tok) {
<example>
<title><function>strtolower</function> example</title>
<programlisting role="php">
<![CDATA[
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtolower($str);
print $str; # Prints mary had a little lamb and she loved it so
]]>
</programlisting>
</example>
<para>
@ -3311,9 +3389,11 @@ print $str; # Prints mary had a little lamb and she loved it so
<example>
<title><function>strtoupper</function> example</title>
<programlisting role="php">
<![CDATA[
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtoupper($str);
print $str; # Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
]]>
</programlisting>
</example>
<para>
@ -3377,7 +3457,9 @@ print $str; # Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
<example>
<title><function>str_replace</function> example</title>
<programlisting role="php">
$bodytag = str_replace("%body%", "black", "&lt;body text=%body%>");
<![CDATA[
$bodytag = str_replace("%body%", "black", "<body text=%body%>");
]]>
</programlisting>
</example>
</para>
@ -3425,7 +3507,9 @@ $bodytag = str_replace("%body%", "black", "&lt;body text=%body%>");
<example>
<title><function>strtr</function> example</title>
<programlisting role="php">
<![CDATA[
$addr = strtr($addr, "äåö", "aao");
]]>
</programlisting>
</example>
</para>
@ -3442,8 +3526,10 @@ $addr = strtr($addr, "
Examples:
<informalexample>
<programlisting role="php">
$trans = array("hello" =&gt; "hi", "hi" =&gt; "hello");
<![CDATA[
$trans = array("hello" => "hi", "hi" => "hello");
echo strtr("hi all, I said hello", $trans) . "\n";
]]>
</programlisting>
</informalexample>
This will show: "hello all, I said hi",
@ -3494,8 +3580,10 @@ echo strtr("hi all, I said hello", $trans) . "\n";
Examples:
<informalexample>
<programlisting role="php">
<![CDATA[
$rest = substr("abcdef", 1); // returns "bcdef"
$rest = substr("abcdef", 1, 3); // returns "bcd"
]]>
</programlisting>
</informalexample>
</para>
@ -3507,9 +3595,11 @@ $rest = substr("abcdef", 1, 3); // returns "bcd"
Examples:
<informalexample>
<programlisting role="php">
<![CDATA[
$rest = substr("abcdef", -1); // returns "f"
$rest = substr("abcdef", -2); // returns "ef"
$rest = substr("abcdef", -3, 1); // returns "d"
]]>
</programlisting>
</informalexample>
</para>
@ -3533,7 +3623,9 @@ $rest = substr("abcdef", -3, 1); // returns "d"
Examples:
<informalexample>
<programlisting role="php">
<![CDATA[
$rest = substr("abcdef", 1, -1); // returns "bcde"
]]>
</programlisting>
</informalexample>
</para>
@ -3568,7 +3660,9 @@ $rest = substr("abcdef", 1, -1); // returns "bcde"
<example>
<title><function>substr_count</function> example</title>
<programlisting>
<![CDATA[
print substr_count("This is a test", "is"); // prints out 2
]]>
</programlisting>
</example>
</para>
@ -3624,24 +3718,26 @@ print substr_count("This is a test", "is"); // prints out 2
<example>
<title><function>substr_replace</function> example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$var = 'ABCDEFGH:/MNRPQR/';
echo "Original: $var&lt;hr&gt;\n";
echo "Original: $var<hr>\n";
/* These two examples replace all of $var with 'bob'. */
echo substr_replace($var, 'bob', 0) . "&lt;br&gt;\n";
echo substr_replace($var, 'bob', 0, strlen($var)) . "&lt;br&gt;\n";
echo substr_replace($var, 'bob', 0) . "<br>\n";
echo substr_replace($var, 'bob', 0, strlen($var)) . "<br>\n";
/* Insert 'bob' right at the beginning of $var. */
echo substr_replace($var, 'bob', 0, 0) . "&lt;br&gt;\n";
echo substr_replace($var, 'bob', 0, 0) . "<br>\n";
/* These next two replace 'MNRPQR' in $var with 'bob'. */
echo substr_replace($var, 'bob', 10, -1) . "&lt;br&gt;\n";
echo substr_replace($var, 'bob', -7, -1) . "&lt;br&gt;\n";
echo substr_replace($var, 'bob', 10, -1) . "<br>\n";
echo substr_replace($var, 'bob', -7, -1) . "<br>\n";
/* Delete 'MNRPQR' from $var. */
echo substr_replace($var, '', 10, -1) . "&lt;br&gt;\n";
?&gt;
echo substr_replace($var, '', 10, -1) . "<br>\n";
?>
]]>
</programlisting>
</example>
</para>
@ -3788,12 +3884,14 @@ $clean = trim($binary,"\0x00..\0x1F");
<example>
<title><function>ucfirst</function> example</title>
<programlisting role="php">
<![CDATA[
$foo = 'hello world!';
$foo = ucfirst($foo); // Hello world!
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
]]>
</programlisting>
</example>
</para>
@ -3826,12 +3924,14 @@ $bar = ucfirst(strtolower($bar)); // Hello world!
<example>
<title><function>ucwords</function> example</title>
<programlisting role="php">
<![CDATA[
$foo = 'hello world!';
$foo = ucwords($foo); // Hello World!
$bar = 'HELLO WORLD!';
$bar = ucwords($bar); // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
]]>
</programlisting>
</example>
<note>
@ -3965,10 +4065,12 @@ $bar = ucwords(strtolower($bar)); // Hello World!
<example>
<title><function>wordwrap</function> example</title>
<programlisting role="php">
<![CDATA[
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap( $text, 20 );
echo "$newtext\n";
]]>
</programlisting>
</example>
</para>
@ -3977,20 +4079,24 @@ echo "$newtext\n";
</para>
<para>
<informalexample>
<programlisting>
<screen>
<![CDATA[
The quick brown fox
jumped over the lazy dog.
</programlisting>
]]>
</screen>
</informalexample>
</para>
<para>
<example>
<title><function>wordwrap</function> example</title>
<programlisting role="php">
<![CDATA[
$text = "A very long woooooooooooord.";
$newtext = wordwrap( $text, 8, "\n", 1);
echo "$newtext\n";
]]>
</programlisting>
</example>
</para>
@ -3999,12 +4105,14 @@ echo "$newtext\n";
</para>
<para>
<informalexample>
<programlisting>
<screen>
<![CDATA[
A very
long
wooooooo
ooooord.
</programlisting>
]]>
</screen>
</informalexample>
</para>
<para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.24 $ -->
<!-- $Revision: 1.25 $ -->
<reference id="ref.swf">
<title>Shockwave Flash functions</title>
<titleabbrev>SWF</titleabbrev>
@ -25,7 +25,8 @@
<example>
<title>SWF example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
swf_openfile ("test.swf", 256, 256, 30, 1, 1, 1);
swf_ortho2 (-100, 100, -100, 100);
swf_defineline (1, -70, 0, 70, 0, .2);
@ -43,7 +44,7 @@ swf_translate (-50, 80, 0);
swf_placeobject (11, 60);
swf_popmatrix ();
for ($i = 0; $i &lt; 30; $i++) {
for ($i = 0; $i < 30; $i++) {
$p = $i/(30-1);
swf_pushmatrix ();
swf_scale (1-($p*.9), 1, 1);
@ -58,7 +59,7 @@ for ($i = 0; $i &lt; 30; $i++) {
swf_showframe ();
}
for ($i = 0; $i &lt; 30; $i++) {
for ($i = 0; $i < 30; $i++) {
swf_removeobject (50);
if (($i%4) == 0) {
swf_showframe ();
@ -70,7 +71,8 @@ swf_actionstop ();
swf_enddoaction ();
swf_closefile ();
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -172,7 +174,8 @@ swf_closefile ();
and saving it in a database
</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
// The $text variable is submitted by the
// user
@ -236,7 +239,8 @@ function swf_savedata ($data)
@mysql_free_result ($sth);
@mysql_close ($dbh);
}
&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -1777,6 +1781,7 @@ function swf_savedata ($data)
<function>swf_addbuttonrecord</function> function example
</title>
<programlisting role="php">
<![CDATA[
swf_startButton ($objid, TYPE_MENUBUTTON);
swf_addButtonRecord (BSDown|BSOver, $buttonImageId, 340);
swf_onCondition (MenuEnter);
@ -1784,6 +1789,7 @@ swf_startButton ($objid, TYPE_MENUBUTTON);
swf_onCondition (MenuExit);
swf_actionGetUrl ("", "_level1");
swf_endButton ();
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.26 $ -->
<!-- $Revision: 1.27 $ -->
<reference id="ref.odbc">
<title>Unified ODBC functions</title>
<titleabbrev>ODBC</titleabbrev>
@ -512,15 +512,19 @@
<example>
<title><function>odbc_fetch_into</function> pre 4.0.6 example </title>
<programlisting role="php">
<![CDATA[
$rc = odbc_fetch_into($res_id, $my_array);
]]>
</programlisting>
<para>
or
</para>
<programlisting role="php">
<![CDATA[
$rc = odbc_fetch_into($res_id, $row, $my_array);
$rc = odbc_fetch_into($res_id, 1, $my_array);
]]>
</programlisting>
</example>
</para>
@ -536,14 +540,18 @@ $rc = odbc_fetch_into($res_id, 1, $my_array);
<example>
<title><function>odbc_fetch_into</function> 4.0.6 example</title>
<programlisting role="php">
<![CDATA[
$rc = odbc_fetch_into($res_id, $my_array);
]]>
</programlisting>
<para>
or
</para>
<programlisting role="php">
<![CDATA[
$row = 1;
$rc = odbc_fetch_into($res_id, $row, $my_array);
]]>
</programlisting>
</example>
</para>
@ -959,8 +967,10 @@ $rc = odbc_fetch_into($res_id, $row, $my_array);
the column number of the field you want; or it can be a string
containing the name of the field. For example:
<informalexample><programlisting>
<![CDATA[
$item_3 = odbc_result ($Query_ID, 3);
$item_val = odbc_result ($Query_ID, "val");
]]>
</programlisting>
</informalexample>
</para>
@ -1105,6 +1115,7 @@ longer than 4096 bytes, the contents is not
<example>
<title>ODBC Setoption Examples</title>
<programlisting role="php">
<![CDATA[
// 1. Option 102 of SQLSetConnectOption() is SQL_AUTOCOMMIT.
// Value 1 of SQL_AUTOCOMMIT is SQL_AUTOCOMMIT_ON.
// This example has the same effect as
@ -1118,6 +1129,7 @@ odbc_setoption ($conn, 1, 102, 1);
$result = odbc_prepare ($conn, $sql);
odbc_setoption ($result, 2, 0, 30);
odbc_execute ($result);
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.19 $ -->
<!-- $Revision: 1.20 $ -->
<reference id="ref.url">
<title>URL Functions</title>
<titleabbrev>URLs</titleabbrev>
@ -138,16 +138,20 @@
<example>
<title><function>rawurlencode</function> example 1</title>
<programlisting role="php">
echo '&lt;a href="ftp://user:', rawurlencode('foo @+%/'),
<![CDATA[
echo '<a href="ftp://user:', rawurlencode('foo @+%/'),
'@ftp.my.com/x.txt">';
]]>
</programlisting>
</example>
Or, if you pass information in a PATH_INFO component of the URL:
<example>
<title><function>rawurlencode</function> example 2</title>
<programlisting role="php">
echo '&lt;a href="http://x.com/department_list_script/',
<![CDATA[
echo '<a href="http://x.com/department_list_script/',
rawurlencode('sales and marketing/Miami'), '">';
]]>
</programlisting>
</example>
</para>
@ -178,14 +182,16 @@ echo '&lt;a href="http://x.com/department_list_script/',
<example>
<title><function>urldecode</function> example</title>
<programlisting role="php">
$a = split('&amp;', $QUERY_STRING);
<![CDATA[
$a = split('&', $QUERY_STRING);
$i = 0;
while ($i &lt; count($a)) {
while ($i < count($a)) {
$b = split('=', $a[$i]);
echo 'Value for parameter ', htmlspecialchars(urldecode($b[0])),
' is ', htmlspecialchars(urldecode($b[1])), "&lt;br>";
$i++;
}
]]>
</programlisting>
</example>
</para>
@ -226,7 +232,9 @@ while ($i &lt; count($a)) {
<example>
<title><function>urlencode</function> example</title>
<programlisting role="php">
echo '&lt;a href="mycgi?foo=', urlencode($userinput), '">';
<![CDATA[
echo '<a href="mycgi?foo=', urlencode($userinput), '">';
]]>
</programlisting>
</example>
</para>
@ -247,7 +255,9 @@ echo '&lt;a href="mycgi?foo=', urlencode($userinput), '">';
<example>
<title><function>urlencode/htmlentities</function> example</title>
<programlisting role="php">
echo '&lt;a href="mycgi?foo=', htmlentities(urlencode($userinput)), '">';
<![CDATA[
echo '<a href="mycgi?foo=', htmlentities(urlencode($userinput)), '">';
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.76 $ -->
<!-- $Revision: 1.77 $ -->
<reference id="ref.variables">
<title>Variable Functions</title>
<titleabbrev>Variables</titleabbrev>
@ -56,6 +56,7 @@
<informalexample>
<programlisting role="php">
<![CDATA[
$var = 0;
if (empty($var)) { // evaluates true
@ -65,6 +66,7 @@ if (empty($var)) { // evaluates true
if (!isset($var)) { // evaluates false
echo '$var is not set at all';
}
]]>
</programlisting>
</informalexample>
@ -103,9 +105,11 @@ if (!isset($var)) { // evaluates false
<function>floatval</function> on arrays or objects.
<informalexample>
<programlisting role="php">
<![CDATA[
$var = '122.34343The';
$float_value_of_var = floatval ($var);
print $float_value_of_var; // prints 122.34343
]]>
</programlisting>
</informalexample>
</para>
@ -226,6 +230,7 @@ print $float_value_of_var; // prints 122.34343
variables.
<informalexample>
<programlisting role="php">
<![CDATA[
$b = array(1,1,2,3,5,8);
$arr = get_defined_vars();
@ -245,6 +250,7 @@ print_r($arr["HTTP_SERVER_VARS"]);
// print all the available keys for the arrays of variables
print_r(array_keys(get_defined_vars()));
]]>
</programlisting>
</informalexample>
</para>
@ -276,6 +282,7 @@ print_r(array_keys(get_defined_vars()));
generates an error.
<informalexample>
<programlisting role="php">
<![CDATA[
$c = mysql_connect();
echo get_resource_type($c)."\n";
// prints: mysql link
@ -287,6 +294,7 @@ echo get_resource_type($fp)."\n";
$doc = new_xmldoc("1.0");
echo get_resource_type($doc->doc)."\n";
// prints: domxml document
]]>
</programlisting>
</informalexample>
</para>
@ -338,9 +346,11 @@ echo get_resource_type($doc->doc)."\n";
</note>
<informalexample>
<programlisting role="php">
<![CDATA[
// This will import GET and POST vars
// with an "rvar_" prefix
import_request_variables("gP", "rvar_");
]]>
</programlisting>
</informalexample>
<simpara>
@ -715,6 +725,7 @@ import_request_variables("gP", "rvar_");
For example:
<informalexample>
<programlisting role="php">
<![CDATA[
<!-- TODO: better example, this one can be quite misleading for unexperienced
programmers -->
function show_var($var) {
@ -740,6 +751,7 @@ show_var($proteins)
// [2]=>
// string(10) "ferredoxin"
// }
]]>
</programlisting>
</informalexample>
</para>
@ -826,6 +838,7 @@ show_var($proteins)
is not equivalent to the PHP &null; constant.
<informalexample>
<programlisting role="php">
<![CDATA[
$a = "test";
echo isset ($a); // TRUE
@ -834,6 +847,7 @@ echo isset ($a); // FALSE
$foo = NULL;
print isset ($foo); // FALSE
]]>
</programlisting>
</informalexample>
</para>
@ -880,10 +894,12 @@ print isset ($foo); // FALSE
<para>
<informalexample>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$a = array (1, 2, array ("a", "b", "c"));
print_r ($a);
?>
]]>
</programlisting>
</informalexample>
</para>
@ -960,6 +976,7 @@ print_r ($a);
<example>
<title><function>serialize</function> example</title>
<programlisting role="php">
<![CDATA[
// $session_data contains a multi-dimensional array with session
// information for the current user. We use serialize() to store
// it in a database at the end of the request.
@ -971,10 +988,11 @@ $sqldata = array (serialize($session_data), $PHP_AUTH_USER);
if (!odbc_execute ($stmt, &amp;$sqldata)) {
$stmt = odbc_prepare($conn,
"INSERT INTO sessions (id, data) VALUES(?, ?)");
if (!odbc_execute($stmt, &amp;$sqldata)) {
if (!odbc_execute($stmt, &$sqldata)) {
/* Something went wrong. Bitch, whine and moan. */
}
}
]]>
</programlisting>
</example>
</para>
@ -1051,11 +1069,13 @@ if (!odbc_execute ($stmt, &amp;$sqldata)) {
<example>
<title><function>settype</function> example</title>
<programlisting role="php">
<![CDATA[
$foo = "5bar"; // string
$bar = true; // boolean
settype($foo, "integer"); // $foo is now 5 (integer)
settype($bar, "string"); // $bar is now "1" (string)
]]>
</programlisting>
</example>
</para>
@ -1136,6 +1156,7 @@ settype($bar, "string"); // $bar is now "1" (string)
<example>
<title><function>unserialize</function> example</title>
<programlisting role="php">
<![CDATA[
// Here, we use unserialize() to load session data from a database
// into $session_data. This example complements the one described
// with <function>serialize</function>.
@ -1154,6 +1175,7 @@ if (!odbc_execute ($stmt, &amp;$sqldata) || !odbc_fetch_into ($stmt, &amp;$tmp))
$session_data = array();
}
}
]]>
</programlisting>
</example>
</para>
@ -1191,6 +1213,7 @@ if (!odbc_execute ($stmt, &amp;$sqldata) || !odbc_fetch_into ($stmt, &amp;$tmp))
<example>
<title><function>unset</function> example</title>
<programlisting role="php">
<![CDATA[
// destroy a single variable
unset ($foo);
@ -1199,6 +1222,7 @@ unset ($bar['quux']);
// destroy more than one variable
unset ($foo1, $foo2, $foo3);
]]>
</programlisting>
</example>
</para>
@ -1214,6 +1238,7 @@ unset ($foo1, $foo2, $foo3);
<function>unset</function> was called.
<informalexample>
<programlisting role="php">
<![CDATA[
function destroy_foo() {
global $foo;
unset($foo);
@ -1222,13 +1247,16 @@ function destroy_foo() {
$foo = 'bar';
destroy_foo();
echo $foo;
]]>
</programlisting>
</informalexample>
The above example would output:
<informalexample>
<programlisting>
<screen>
<![CDATA[
bar
</programlisting>
]]>
</screen>
</informalexample>
</para>
<para>
@ -1239,7 +1267,8 @@ bar
was called.
<informalexample>
<programlisting role="php">
function foo(&amp;$bar) {
<![CDATA[
function foo(&$bar) {
unset($bar);
$bar = "blah";
}
@ -1249,14 +1278,17 @@ echo "$bar\n";
foo($bar);
echo "$bar\n";
]]>
</programlisting>
</informalexample>
The above example would output:
<informalexample>
<programlisting>
<screen>
<![CDATA[
something
something
</programlisting>
]]>
</screen>
</informalexample>
</para>
<para>
@ -1265,6 +1297,7 @@ something
static variable, rather than the static variable itself.
<informalexample>
<programlisting role="php">
<![CDATA[
function foo() {
static $a;
$a++;
@ -1276,27 +1309,32 @@ function foo() {
foo();
foo();
foo();
]]>
</programlisting>
</informalexample>
The above example would output:
<informalexample>
<programlisting>
<screen>
<![CDATA[
1
2
3
</programlisting>
]]>
</screen>
</informalexample>
</para>
<para>
If you would like to <function>unset</function> a global variable inside of a function, you can use the <parameter>$GLOBALS</parameter> array to do so:
<informalexample>
<programlisting role="php">
<![CDATA[
function foo() {
unset($GLOBALS['bar']);
}
$bar = "something";
foo();
]]>
</programlisting>
</informalexample>
</para>
@ -1340,8 +1378,9 @@ foo();
<para>
<informalexample>
<programlisting role="php">
&lt;pre&gt;
&lt;?php
<![CDATA[
<pre>
<?php
$a = array (1, 2, array ("a", "b", "c"));
var_dump ($a);
@ -1372,8 +1411,9 @@ float(3.1)
bool(true)
*/
?&gt;
&lt;/pre&gt;
?>;
</pre>
]]>
</programlisting>
</informalexample>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.13 $ -->
<!-- $Revision: 1.14 $ -->
<reference id="ref.wddx">
<title>WDDX Functions</title>
<titleabbrev>WDDX</titleabbrev>
@ -24,9 +24,12 @@
<example>
<title>Serializing a single value</title>
<programlisting role="php">
&lt;?php
<![CDATA[
</php>
<?php
print wddx_serialize_value("PHP to WDDX packet example", "PHP packet");
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -34,15 +37,18 @@ print wddx_serialize_value("PHP to WDDX packet example", "PHP packet");
This example will produce:
<informalexample>
<programlisting role="php">
&lt;wddxPacket version='1.0'&gt;&lt;header comment='PHP packet'/&gt;&lt;data&gt;
&lt;string&gt;PHP to WDDX packet example&lt;/string&gt;&lt;/data&gt;&lt;/wddxPacket&gt;
<![CDATA[
<wddxPacket version='1.0'><header comment='PHP packet'/><data>
<string>PHP to WDDX packet example</string></data></wddxPacket>
]]>
</programlisting>
</informalexample>
<example>
<title>Using incremental packets</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$pi = 3.1415926;
$packet_id = wddx_packet_start("PHP");
wddx_add_vars($packet_id, "pi");
@ -53,19 +59,22 @@ wddx_add_vars($packet_id, "cities");
$packet = wddx_packet_end($packet_id);
print $packet;
?&gt;
?>
]]>
</programlisting>
</example>
</para>
<para>
This example will produce:
<informalexample>
<programlisting role="php">
&lt;wddxPacket version='1.0'&gt;&lt;header comment='PHP'/&gt;&lt;data&gt;&lt;struct&gt;
&lt;var name='pi'&gt;&lt;number&gt;3.1415926&lt;/number&gt;&lt;/var&gt;&lt;var name='cities'&gt;
&lt;array length='3'&gt;&lt;string&gt;Austin&lt;/string&gt;&lt;string&gt;Novato&lt;/string&gt;
&lt;string&gt;Seattle&lt;/string&gt;&lt;/array&gt;&lt;/var&gt;&lt;/struct&gt;&lt;/data&gt;&lt;/wddxPacket&gt;
</programlisting>
<screen>
<![CDATA[
<wddxPacket version='1.0'><header comment='PHP'/><data><struct>
<var name='pi'><number>3.1415926</number></var><var name='cities'>
<array length='3'><string>Austin</string><string>Novato</string>
<string>Seattle</string></array></var></struct></data></wddxPacket>
]]>
</screen>
</informalexample>
</para>
</partintro>
@ -127,7 +136,7 @@ print $packet;
<example>
<title>wddx_serialize_vars example</title>
<programlisting>
&lt;?php
<?php
$a = 1;
$b = 5.5;
$c = array("blue", "orange", "violet");
@ -135,18 +144,20 @@ $d = "colors";
$clvars = array("c", "d");
print wddx_serialize_vars("a", "b", $clvars);
?&gt;
?>
</programlisting>
</example>
</para>
<para>
The above example will produce:
<programlisting>
&lt;wddxPacket version='1.0'&gt;&lt;header/&gt;&lt;data&gt;&lt;struct&gt;&lt;var name='a'&gt;&lt;number&gt;1&lt;/number&gt;&lt;/var&gt;
&lt;var name='b'&gt;&lt;number&gt;5.5&lt;/number&gt;&lt;/var&gt;&lt;var name='c'&gt;&lt;array length='3'&gt;
&lt;string&gt;blue&lt;/string&gt;&lt;string&gt;orange&lt;/string&gt;&lt;string&gt;violet&lt;/string&gt;&lt;/array&gt;&lt;/var&gt;
&lt;var name='d'&gt;&lt;string&gt;colors&lt;/string&gt;&lt;/var&gt;&lt;/struct&gt;&lt;/data&gt;&lt;/wddxPacket&gt;
</programlisting>
<screen>
<![CDATA[
<wddxPacket version='1.0'><header/><data><struct><var name='a'><number>1</number></var>
<var name='b'><number>5.5</number></var><var name='c'><array length='3'>
<string>blue</string><string>orange</string><string>violet</string></array></var>
<var name='d'><string>colors</string></var></struct></data></wddxPacket>
]]>
</screen>
</para>
</refsect1>
</refentry>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.20 $ -->
<!-- $Revision: 1.21 $ -->
<reference id="ref.xml">
<title>XML parser functions</title>
<titleabbrev>XML</titleabbrev>
@ -25,9 +25,11 @@
Makefile that comes with expat does not build a library by
default, you can use this make rule for that:
<programlisting role="makefile">
<![CDATA[
libexpat.a: $(OBJS)
ar -rc $@ $(OBJS)
ranlib $@
]]>
</programlisting>
A source RPM package of expat can be found at <ulink
url="&url.expat.rpm;">&url.expat.rpm;</ulink>.
@ -273,12 +275,13 @@ libexpat.a: $(OBJS)
<example>
<title>Show XML Element Structure</title>
<programlisting role="php">
<![CDATA[
$file = "data.xml";
$depth = array();
function startElement($parser, $name, $attrs) {
global $depth;
for ($i = 0; $i &lt; $depth[$parser]; $i++) {
for ($i = 0; $i < $depth[$parser]; $i++) {
print " ";
}
print "$name\n";
@ -304,6 +307,7 @@ while ($data = fread($fp, 4096)) {
}
}
xml_parser_free($xml_parser);
]]>
</programlisting>
</example>
</para>
@ -320,24 +324,25 @@ xml_parser_free($xml_parser);
course, this example will only work with a specific XML
document type.
<programlisting role="php">
<![CDATA[
$file = "data.xml";
$map_array = array(
"BOLD" =&gt; "B",
"EMPHASIS" =&gt; "I",
"LITERAL" =&gt; "TT"
"BOLD" => "B",
"EMPHASIS" => "I",
"LITERAL" => "TT"
);
function startElement($parser, $name, $attrs) {
global $map_array;
if ($htmltag = $map_array[$name]) {
print "&lt;$htmltag&gt;";
print "<$htmltag>";
}
}
function endElement($parser, $name) {
global $map_array;
if ($htmltag = $map_array[$name]) {
print "&lt;/$htmltag&gt;";
print "</$htmltag>";
}
}
@ -362,6 +367,7 @@ while ($data = fread($fp, 4096)) {
}
}
xml_parser_free($xml_parser);
]]>
</programlisting>
</para>
</example>
@ -385,34 +391,35 @@ xml_parser_free($xml_parser);
<example>
<title>External Entity Example</title>
<programlisting role="php">
<![CDATA[
$file = "xmltest.xml";
function trustedFile($file) {
// only trust local files owned by ourselves
if (!eregi("^([a-z]+)://", $file)
&amp;&amp; fileowner($file) == getmyuid()) {
&& fileowner($file) == getmyuid()) {
return true;
}
return false;
}
function startElement($parser, $name, $attribs) {
print "&amp;lt;&lt;font color=\"#0000cc\"&gt;$name&lt;/font&gt;";
print "&lt;<font color=\"#0000cc\">$name</font>";
if (sizeof($attribs)) {
while (list($k, $v) = each($attribs)) {
print " &lt;font color=\"#009900\"&gt;$k&lt;/font&gt;=\"&lt;font
color=\"#990000\"&gt;$v&lt;/font&gt;\"";
print " <font color=\"#009900\">$k</font>=\"<font
color=\"#990000\">$v</font>\"";
}
}
print "&amp;gt;";
print "&gt;";
}
function endElement($parser, $name) {
print "&amp;lt;/&lt;font color=\"#0000cc\"&gt;$name&lt;/font&gt;&amp;gt;";
print "&lt;/<font color=\"#0000cc\">$name</font>&gt;";
}
function characterData($parser, $data) {
print "&lt;b&gt;$data&lt;/b&gt;";
print "<b>$data</b>";
}
function PIHandler($parser, $target, $data) {
@ -425,7 +432,7 @@ function PIHandler($parser, $target, $data) {
if (trustedFile($parser_file[$parser])) {
eval($data);
} else {
printf("Untrusted PHP code: &lt;i&gt;%s&lt;/i&gt;",
printf("Untrusted PHP code: <i>%s</i>",
htmlspecialchars($data));
}
break;
@ -433,11 +440,11 @@ function PIHandler($parser, $target, $data) {
}
function defaultHandler($parser, $data) {
if (substr($data, 0, 1) == "&amp;" &amp;&amp; substr($data, -1, 1) == ";") {
printf('&lt;font color="#aa00aa"&gt;%s&lt;/font&gt;',
if (substr($data, 0, 1) == "&" && substr($data, -1, 1) == ";") {
printf('<font color="#aa00aa">%s</font>',
htmlspecialchars($data));
} else {
printf('&lt;font size="-1"&gt;%s&lt;/font&gt;',
printf('<font size="-1">%s</font>',
htmlspecialchars($data));
}
}
@ -491,7 +498,7 @@ if (!(list($xml_parser, $fp) = new_xml_parser($file))) {
die("could not open XML input");
}
print "&lt;pre&gt;";
print "<pre>";
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d\n",
@ -499,11 +506,12 @@ while ($data = fread($fp, 4096)) {
xml_get_current_line_number($xml_parser)));
}
}
print "&lt;/pre&gt;";
print "</pre>";
print "parse complete\n";
xml_parser_free($xml_parser);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -511,33 +519,35 @@ xml_parser_free($xml_parser);
<example>
<title>xmltest.xml</title>
<programlisting role="xml">
&lt;?xml version='1.0'?&gt;
&lt;!DOCTYPE chapter SYSTEM "/just/a/test.dtd" [
&lt;!ENTITY plainEntity "FOO entity"&gt;
&lt;!ENTITY systemEntity SYSTEM "xmltest2.xml"&gt;
]&gt;
&lt;chapter&gt;
&lt;TITLE&gt;Title &amp;plainEntity;&lt;/TITLE&gt;
&lt;para&gt;
&lt;informaltable&gt;
&lt;tgroup cols="3"&gt;
&lt;tbody&gt;
&lt;row&gt;&lt;entry&gt;a1&lt;/entry&gt;&lt;entry morerows="1"&gt;b1&lt;/entry&gt;&lt;entry&gt;c1&lt;/entry&gt;&lt;/row&gt;
&lt;row&gt;&lt;entry&gt;a2&lt;/entry&gt;&lt;entry&gt;c2&lt;/entry&gt;&lt;/row&gt;
&lt;row&gt;&lt;entry&gt;a3&lt;/entry&gt;&lt;entry&gt;b3&lt;/entry&gt;&lt;entry&gt;c3&lt;/entry&gt;&lt;/row&gt;
&lt;/tbody&gt;
&lt;/tgroup&gt;
&lt;/informaltable&gt;
&lt;/para&gt;
&amp;systemEntity;
&lt;sect1 id="about"&gt;
&lt;title&gt;About this Document&lt;/title&gt;
&lt;para&gt;
&lt;!-- this is a comment --&gt;
&lt;?php print 'Hi! This is PHP version '.phpversion(); ?&gt;
&lt;/para&gt;
&lt;/sect1&gt;
&lt;/chapter&gt;
<![CDATA[
<?xml version='1.0'?>
<!DOCTYPE chapter SYSTEM "/just/a/test.dtd" [
<!ENTITY plainEntity "FOO entity">
<!ENTITY systemEntity SYSTEM "xmltest2.xml">
]>
<chapter>
<TITLE>Title &plainEntity;</TITLE>
<para>
<informaltable>
<tgroup cols="3">
<tbody>
<row><entry>a1</entry><entry morerows="1">b1</entry><entry>c1</entry></row>
<row><entry>a2</entry><entry>c2</entry></row>
<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
</tbody>
</tgroup>
</informaltable>
</para>
&systemEntity;
<sect1 id="about">
<title>About this Document</title>
<para>
<!-- this is a comment -->
<?php print 'Hi! This is PHP version '.phpversion(); ?>
</para>
</sect1>
</chapter>
]]>
</programlisting>
</example>
</para>
@ -546,15 +556,17 @@ xml_parser_free($xml_parser);
<example>
<title>xmltest2.xml</title>
<programlisting role="xml">
&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE foo [
&lt;!ENTITY testEnt "test entity"&gt;
]&gt;
&lt;foo&gt;
&lt;element attrib="value"/&gt;
&amp;testEnt;
&lt;?php print "This is some more PHP code being executed."; ?&gt;
&lt;/foo&gt;
<![CDATA[
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY testEnt "test entity">
]>
<foo>
<element attrib="value"/>
&testEnt;
<?php print "This is some more PHP code being executed."; ?>
</foo>
]]>
</programlisting>
</example>
</para>
@ -622,19 +634,20 @@ xml_parser_free($xml_parser);
assumed to be methods of <parameter>object</parameter>.
</para>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
class xml {
var $parser;
function xml() {
$this-&gt;parser = xml_parser_create();
xml_set_object($this-&gt;parser,&amp;$this);
xml_set_element_handler($this-&gt;parser,"tag_open","tag_close");
xml_set_character_data_handler($this-&gt;parser,"cdata");
$this->parser = xml_parser_create();
xml_set_object($this->parser,&$this);
xml_set_element_handler($this->parser,"tag_open","tag_close");
xml_set_character_data_handler($this->parser,"cdata");
}
function parse($data) {
xml_parse($this-&gt;parser,$data);
xml_parse($this->parser,$data);
}
function tag_open($parser,$tag,$attributes) {
@ -652,8 +665,9 @@ function tag_close($parser,$tag) {
} // end of class xml
$xml_parser = new xml();
$xml_parser-&gt;parse("&lt;A ID=\"hallo\"&gt;PHP&lt;/A&gt;");
?&gt;
$xml_parser->parse("<A ID=\"hallo\">PHP</A>");
?>
]]>
</programlisting>
</refsect1>
</refentry>
@ -1653,8 +1667,9 @@ $xml_parser-&gt;parse("&lt;A ID=\"hallo\"&gt;PHP&lt;/A&gt;");
<literal>para</literal> tag, and then we parse this an print out
the structures generated:
<informalexample>
<programlisting>
$simple = &quot;&lt;para&gt;&lt;note&gt;simple note&lt;/note&gt;&lt;/para&gt;&quot;;
<programlisting role="php">
<![CDATA[
$simple = &quot;<para><note>simple note</note></para>&quot;;
$p = xml_parser_create();
xml_parse_into_struct($p,$simple,$vals,$index);
xml_parser_free($p);
@ -1662,23 +1677,25 @@ echo "Index array\n";
print_r($index);
echo "\nVals array\n";
print_r($vals);
]]>
</programlisting>
</informalexample>
When we run that code, the output will be:
<informalexample>
<programlisting>
<screen>
<![CDATA[
Index array
Array
(
[PARA] =&gt; Array
[PARA] => Array
(
[0] =&gt; 0
[1] =&gt; 2
[0] => 0
[1] => 2
)
[NOTE] =&gt; Array
[NOTE] => Array
(
[0] =&gt; 1
[0] => 1
)
)
@ -1686,30 +1703,31 @@ Array
Vals array
Array
(
[0] =&gt; Array
[0] => Array
(
[tag] =&gt; PARA
[type] =&gt; open
[level] =&gt; 1
[tag] => PARA
[type] => open
[level] => 1
)
[1] =&gt; Array
[1] => Array
(
[tag] =&gt; NOTE
[type] =&gt; complete
[level] =&gt; 2
[value] =&gt; simple note
[tag] => NOTE
[type] => complete
[level] => 2
[value] => simple note
)
[2] =&gt; Array
[2] => Array
(
[tag] =&gt; PARA
[type] =&gt; close
[level] =&gt; 1
[tag] => PARA
[type] => close
[level] => 1
)
)
</programlisting>
]]>
</screen>
</informalexample>
</para>
<para>
@ -1722,25 +1740,27 @@ Array
representing a small database of aminoacids information:
<example>
<title>moldb.xml - small database of molecular information</title>
<programlisting>
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;moldb&gt;
<programlisting role="xml">
<![CDATA[
<?xml version="1.0"?>
<moldb>
&lt;molecule&gt;
&lt;name&gt;Alanine&lt;/name&gt;
&lt;symbol&gt;ala&lt;/symbol&gt;
&lt;code&gt;A&lt;/code&gt;
&lt;type&gt;hydrophobic&lt;/type&gt;
&lt;/molecule&gt;
<molecule>
<name>Alanine</name>
<symbol>ala</symbol>
<code>A</code>
<type>hydrophobic</type>
</molecule>
&lt;molecule&gt;
&lt;name&gt;Lysine&lt;/name&gt;
&lt;symbol&gt;lys&lt;/symbol&gt;
&lt;code&gt;K&lt;/code&gt;
&lt;type&gt;charged&lt;/type&gt;
&lt;/molecule&gt;
<molecule>
<name>Lysine</name>
<symbol>lys</symbol>
<code>K</code>
<type>charged</type>
</molecule>
&lt;/moldb&gt;
</moldb>
]]>
</programlisting>
</example>
And some code to parse the document and generate the appropriate
@ -1751,7 +1771,8 @@ Array
molecular objects
</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
class AminoAcid {
var $name; // aa name
@ -1760,8 +1781,8 @@ class AminoAcid {
var $type; // hydrophobic, charged or neutral
function AminoAcid ($aa) {
foreach ($aa as $k=&gt;$v)
$this-&gt;$k = $aa[$k];
foreach ($aa as $k=>$v)
$this->$k = $aa[$k];
}
}
@ -1775,12 +1796,12 @@ function readDatabase($filename) {
xml_parser_free($parser);
// loop through the structures
foreach ($tags as $key=&gt;$val) {
foreach ($tags as $key=>$val) {
if ($key == &quot;molecule&quot;) {
$molranges = $val;
// each contiguous pair of array entries are the
// lower and upper range for each molecule definition
for ($i=0; $i &lt; count($molranges); $i+=2) {
for ($i=0; $i < count($molranges); $i+=2) {
$offset = $molranges[$i] + 1;
$len = $molranges[$i + 1] - $offset;
$tdb[] = parseMol(array_slice($values, $offset, $len));
@ -1793,7 +1814,7 @@ function readDatabase($filename) {
}
function parseMol($mvalues) {
for ($i=0; $i &lt; count($mvalues); $i++)
for ($i=0; $i < count($mvalues); $i++)
$mol[$mvalues[$i][&quot;tag&quot;]] = $mvalues[$i][&quot;value&quot;];
return new AminoAcid($mol);
}
@ -1802,7 +1823,8 @@ $db = readDatabase(&quot;moldb.xml&quot;);
echo "** Database of AminoAcid objects:\n";
print_r($db);
?&gt;
?>
]]>
</programlisting>
</example>
After executing <filename>parsemoldb.php</filename>, the variable
@ -1810,28 +1832,30 @@ print_r($db);
<classname>AminoAcid</classname> objects, and the output of the
script confirms that:
<informalexample>
<programlisting>
<screen>
<![CDATA[
** Database of AminoAcid objects:
Array
(
[0] =&gt; aminoacid Object
[0] => aminoacid Object
(
[name] =&gt; Alanine
[symbol] =&gt; ala
[code] =&gt; A
[type] =&gt; hydrophobic
[name] => Alanine
[symbol] => ala
[code] => A
[type] => hydrophobic
)
[1] =&gt; aminoacid Object
[1] => aminoacid Object
(
[name] =&gt; Lysine
[symbol] =&gt; lys
[code] =&gt; K
[type] =&gt; charged
[name] => Lysine
[symbol] => lys
[code] => K
[type] => charged
)
)
</programlisting>
]]>
</screen>
</informalexample>
</para>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.24 $ -->
<!-- $Revision: 1.25 $ -->
<reference id="ref.xslt">
<title>XSLT functions</title>
<titleabbrev>XSLT</titleabbrev>
@ -262,7 +262,8 @@
Transforming output through an XSLT stylesheet, using the DOM-XML functions for xml generation
</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$xsl_file = "article.xsl";
xslt_output_begintransform($xsl_file);
@ -279,6 +280,7 @@ $article->new_child('body', 'Back after WWI, Italy gained South Tyrol from
echo $doc->dumpmem();
xslt_output_endtransform();
]]>
</programlisting>
</example>
</para>
@ -339,48 +341,49 @@ xslt_output_endtransform();
<example>
<title>Using the <function>xslt_process</function> to transform three strings</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$xslData = '&lt;xsl:stylesheet
$xslData = '<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
&lt;xsl:template match="article"&gt;
&lt;table border="1" cellpadding="2" cellspacing="1"&gt;
&lt;tr&gt;
&lt;td width="20%"&gt;
<xsl:template match="article">
<table border="1" cellpadding="2" cellspacing="1">
<tr>
<td width="20%">
&amp;#160;
&lt;/td&gt;
&lt;td width="80%"&gt;
&lt;h2&gt;&lt;xsl:value-of select="title"/&gt;&lt;/h2&gt;
&lt;h3&gt;&lt;xsl:value-of select="author"/&gt;&lt;/h3&gt;
&lt;br/&gt;
</td>
<td width="80%">
<h2><xsl:value-of select="title"/></h2>
<h3><xsl:value-of select="author"/></h3>
<br/>
&lt;xsl:copy-of select="p"/&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/xsl:template&gt;
<xsl:copy-of select="p"/>
</td>
</tr>
</table>
</xsl:template>
&lt;/xsl:stylesheet&gt;';
</xsl:stylesheet>';
$xmlData = '&lt;?xml version="1.0"?&gt;
&lt;article&gt;
&lt;title&gt;Learning German&lt;/title&gt;
&lt;author&gt;Sterling Hughes&lt;/author&gt;
&lt;p&gt;
$xmlData = '<?xml version="1.0"?>
<article>
<title>Learning German</title>
<author>Sterling Hughes</author>
<p>
Essential phrases:
&lt;br/&gt;
K&amp;#246;nnen Sie mir sagen, wo die Toilette ist?&lt;br/&gt;
Ein grosses Bier, bitte!&lt;br/&gt;
Noch eins, bitte.&lt;br/&gt;
&lt;/p&gt;
&lt;/article&gt;';
<br/>
K#246;nnen Sie mir sagen, wo die Toilette ist?<br/>
Ein grosses Bier, bitte!<br/>
Noch eins, bitte.<br/>
</p>
</article>';
if (xslt_process($xslData, $xmlData, $result)) {
echo "Here is the brilliant in-depth article on learning";
echo " German: ";
echo "&lt;br>\n&lt;br>";
echo "<br>\n<br>";
echo $result;
} else {
echo "There was an error that occurred in the XSL transformation...\n";
@ -389,6 +392,7 @@ if (xslt_process($xslData, $xmlData, $result)) {
exit;
}
?>
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.21 $ -->
<!-- $Revision: 1.22 $ -->
<reference id="ref.yaz">
<title>YAZ functions</title>
<titleabbrev>YAZ</titleabbrev>
@ -39,7 +39,8 @@
</para>
<para>
<informalexample>
<programlisting>
<programlisting role="shell">
<![CDATA[
gunzip -c yaz-1.6.tar.gz|tar xf -
gunzip -c php-4.0.X.tar.gz|tar xf -
cd yaz-1.6
@ -50,6 +51,7 @@ cd ../php-4.0.X
./configure --with-yaz=/usr/bin
make
make install
]]>
</programlisting>
</informalexample>
</para>
@ -71,33 +73,34 @@ make install
host.
</simpara>
<programlisting role="php">
<![CDATA[
$num_hosts = count ($host);
if (empty($term) || count($host) == 0) {
echo '&lt;form method="get"&gt;
&lt;input type="checkbox"
name="host[]" value="bagel.indexdata.dk/gils"&gt;
echo '<form method="get">
<input type="checkbox"
name="host[]" value="bagel.indexdata.dk/gils">
GILS test
&lt;input type="checkbox"
name="host[]" value="localhost:9999/Default"&gt;
<input type="checkbox"
name="host[]" value="localhost:9999/Default">
local test
&lt;input type="checkbox" checked="1"
name="host[]" value="z3950.bell-labs.com/books"&gt;
<input type="checkbox" checked="1"
name="host[]" value="z3950.bell-labs.com/books">
BELL Labs Library
&lt;br>
<br>
RPN Query:
&lt;input type="text" size="30" name="term"&gt;
&lt;input type="submit" name="action" value="Search"&gt;
<input type="text" size="30" name="term">
<input type="submit" name="action" value="Search">
';
} else {
echo 'You searced for ' . htmlspecialchars($term) . '&lt;br&gt;';
for ($i = 0; $i &lt; $num_hosts; $i++) {
echo 'You searced for ' . htmlspecialchars($term) . '<br>';
for ($i = 0; $i < $num_hosts; $i++) {
$id[] = yaz_connect($host[$i]);
yaz_syntax($id[$i],"sutrs");
yaz_search($id[$i],"rpn",$term);
}
yaz_wait();
for ($i = 0; $i &lt; $num_hosts; $i++) {
echo '&lt;hr&gt;' . $host[$i] . ":";
for ($i = 0; $i < $num_hosts; $i++) {
echo '<hr>' . $host[$i] . ":";
$error = yaz_error($id[$i]);
if (!empty($error)) {
echo "Error: $error";
@ -105,17 +108,18 @@ if (empty($term) || count($host) == 0) {
$hits = yaz_hits($id[$i]);
echo "Result Count $hits";
}
echo '&lt;dl&gt;';
for ($p = 1; $p &lt;= 10; $p++) {
echo '<dl>';
for ($p = 1; $p <= 10; $p++) {
$rec = yaz_record($id[$i],$p,"string");
if (empty($rec)) continue;
echo "&lt;dt&gt;&lt;b&gt;$p&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;";
echo ereg_replace("\n", "&lt;br&gt;\n",$rec);
echo "&lt;/dd&gt;";
echo "<dt><b>$p</b></dt><dd>";
echo ereg_replace("\n", "<br>\n",$rec);
echo "</dd>";
}
echo '&lt;/dl&gt;';
echo '</dl>';
}
}
]]>
</programlisting>
</example>
</para>
@ -650,29 +654,31 @@ element set names. For those, piggyback should be disabled.
<example>
<title>PHP function that scans titles</title>
<programlisting>
<![CDATA[
function scan_titles($id, $starterm) {
yaz_scan($id,"rpn", "@attr 1=4 " . $starterm);
yaz_wait();
$errno = yaz_errno($id);
if ($errno == 0) {
$ar = yaz_scan_result($id,&amp;$options);
$ar = yaz_scan_result($id,&$options);
echo 'Scan ok; ';
$ar = yaz_scan_result($id, &amp;$options);
$ar = yaz_scan_result($id, &$options);
while(list($key,$val)=each($options)) {
echo "$key = $val &nbsp;";
}
echo '&lt;br>&lt;table>&lt;tr>&lt;td>';
echo '<br><table><tr><td>';
while(list($key,list($k, $term, $tcount))=each($ar)) {
if (empty($k)) continue;
echo "&lt;tr>&lt;td>$term&lt;/td>&lt;td>";
echo "<tr><td>$term</td><td>";
echo $tcount;
echo "&lt;/td>&lt;/tr>";
echo "</td></tr>";
}
echo '&lt;/table>';
echo '</table>';
} else {
echo "Scan failed. Error: " . yaz_error($id) . "&lt;br>";
echo "Scan failed. Error: " . yaz_error($id) . "<br>";
}
}
]]>
</programlisting>
</example>
</para>
@ -748,10 +754,12 @@ element set names. For those, piggyback should be disabled.
target ID.
</simpara>
<programlisting>
<![CDATA[
$field["ti"] = "1=4";
$field["au"] = "1=1";
$field["isbn"] = "1=7";
yaz_ccl_conf($id,$field);
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.14 $ -->
<!-- $Revision: 1.15 $ -->
<reference id="ref.zip">
<title>Zip File Functions (Read Only Access)</title>
<titleabbrev>Zip</titleabbrev>
@ -41,7 +41,8 @@
<example>
<title>Zip Usage Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$zip = zip_open("/tmp/test2.zip");
@ -68,7 +69,8 @@ if ($zip) {
}
?&gt;
?>
]]>
</programlisting>
</example>
</sect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.19 $ -->
<!-- $Revision: 1.20 $ -->
<reference id="ref.zlib">
<title>Zlib Compression Functions</title>
<titleabbrev>Zlib</titleabbrev>
@ -40,11 +40,12 @@
</para>
<example>
<title>Small Zlib Example</title>
<programlisting role="php">
&lt;?php
<programlisting role="php">
<![CDATA[
<?php
$filename = tempnam ('/tmp', 'zlibtest').'.gz';
print "&lt;html>\n&lt;head>&lt;/head>\n&lt;body>\n&lt;pre>\n";
print "<html>\n<head></head>\n<body>\n<pre>\n";
$s = "Only a test, test, test, test, test, test, test, test!\n";
// open file for writing with maximum compression
@ -72,9 +73,10 @@ if (readgzfile($filename) != strlen($s)) {
echo "Error with zlib functions!";
}
unlink($filename);
print "&lt;/pre>\n&lt;/h1>&lt;/body>\n&lt;/html>\n";
print "</pre>\n</h1></body>\n</html>\n";
?>
]]>
</programlisting>
</example>
</sect1>
@ -314,7 +316,9 @@ print "&lt;/pre>\n&lt;/h1>&lt;/body>\n&lt;/html>\n";
<example>
<title><function>gzopen</function> Example</title>
<programlisting role="php">
<![CDATA[
$fp = gzopen ("/tmp/file.gz", "r");
]]>
</programlisting>
</example>
</para>
@ -405,11 +409,13 @@ $fp = gzopen ("/tmp/file.gz", "r");
<para>
<informalexample>
<programlisting role="php">
<![CDATA[
// get contents of a gz-file into a string
$filename = "/usr/local/something.txt.gz";
$zd = gzopen ($filename, "r");
$contents = gzread ($zd, 10000);
gzclose ($zd);
]]>
</programlisting>
</informalexample>
</para>
@ -787,13 +793,15 @@ gzclose ($zd);
<example>
<title>Creating a gzip file</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$data = implode("", "bigfile.txt");
$gzdata = gzencode($data, 9);
$fp = fopen("bigfile.txt.gz", "w");
fwrite($fp, $gzdata);
fclose($fp);
?&gt;
?>
]]>
</programlisting>
</example>
</para>