Login   Register  
PHP Classes
elePHPant
Icontem

File: PHP_functions-instructions.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Joseph  >  Regulate XHTML Text  >  PHP_functions-instructions.php  >  Download  
File: PHP_functions-instructions.php
Role: Auxiliary script
Content type: text/plain
Description: How to use the RegulateText Class (XHTMLencode) and others
Class: Regulate XHTML Text
Encode characters in text in HTML tags
Author: By
Last change: .
Date: 2011-06-17 12:00
Size: 27,944 bytes
 

Contents

Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>PHP_functions.php Instructions from SoftMoon WebWare: Custom Website Software Development for the 21st Century</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="tsWebEditor (tswebeditor.net.tc - www.tswebeditor.tk)" />
<style type="text/css">
body, div, h1, h2, h4, img, ul, li, a {
	margin: 0;
	padding: 0; }
body {
	min-width: 800px;
	font-family: Times, "Times New Roman", serif;
	color: #000000;
	background: #FFDEAD url(images/SoftMoon.repeat-y.png) repeat-y; }
#top {
	position: relative;
	height: 700px;
	min-height: 42em;
	min-width: 57em;
	background: #FFDEAD url(images/SoftMoon.repeat-x.png) repeat-x; }
#top, #content, #footer {
	opacity: .62;
	-moz-opacity: .62;
	filter: alpha(opacity=62); }
#logo {
	position: absolute;
	top: 2.618em;
	left: 1em;
	font-size: 1.618em; /*for alt text*/
	font-weight: bold;
	line-height: 150%; }
#top h1, #top h2 {
	font-size: 1.618em;
	font-weight: bold; }
#top h1 {
	font-family: "Cooper Black", serif;
	padding: .618em 0 0 1em; }
#top h2 {
	position: absolute;
	bottom: 17px;
	left: 0px;
	text-align: center;
	width: 100%; }
#top h2 span.motto {
	display: block;
	font-style: oblique; }
#top h2 span em {
	text-transform: uppercase;
	font-weight: bold }
#top ul {
	position: absolute;
	bottom: 13em;
	right: 7px;
	z-index: 618;
  color: #000000;
	font-size: 1.382em;
	list-style-type: none;
	overflow: visible; }
#top ul#sub_nav {
	position: relative;
	top: 0;
	right: 0;
	font-size: 100%;
	margin-left: 1.618em; }
#top ul a {
	display: block;
	padding: 0 2px 1px 2px;
 	color: #000080; }
#top ul a:visited {
 	color: #000080; }
#top ul a:hover {
 	color: #FFFF00;
	background-color: #000080;
	text-decoration: none; }
#top li.current {
	font-weight: bold;
	font-style: oblique;
	position: relative;  /*Safari, Google, and Opera all fail to render this at all */
	right: 3.618em; }
#content {
	min-width: 57em;
	width: 100%;  /* fix MS and IE: crash 'n' trash  (yet another "hasLayout" bug?) */
	background: #FFDEAD;
	text-align: center; }
#content h2 {
	margin-top: 2em; }
#content p {
	text-align: justify;
	text-indent: -.618em;
	font-size: 1.236em;
	width: 27em;
	margin: 0 auto 0 auto;
	padding: 0 1em 1em 1em; }
#content p:first-letter {
	font-size: 1.618em;
	font-weight: bold;
	color: #000040; }
#content #noteConstruction { font-size: 1em; }
#content samp, #content code {
  white-space: nowrap;
  font-size: .854076em; }
#content .example {
	width: 37em;
	font-size: 1.236em;
	text-align: left;
	margin: 0 auto 0 auto; }
code { display: inline; }
.example code, .example samp {
	display: block;
  white-space: pre; }
div.fixFirefox { /*we would only need target -samp- if Firefox would recognize this*/
	text-decoration: underline;
  background-color: #FFFFFF; }
#footer {
	position: relative;
	min-width: 57em;
	height: 100px;
	background: #FFDEAD url(images/SoftMoon.footer.back.png) repeat-x bottom; }
#footer p {
	position: absolute;
	left: 1.618em;
	bottom: .618em;
	font-size: .78em;
	font-weight: bold; }
span.numerance {
	font-size: .618em;
	vertical-align: .618em;
	line-height: 100%; }
span.macronym {
	display: inline;
	font-size: .763924em;
	vertical-align: .236076em;
	line-height: 100%; }
</style>
<!--[if IE]>
<style type="text/css">
#top li { display: inline; }
</style>
<![endif]-->
</head>
<body>
<div id='top'>
<h1>Custom Website Software Development for the 21<span class='numerance'>st</span> Century<span class='macronym'>&trade;</span></h1>
<img id='logo' src="images/SoftMoon.gif" alt="SoftMoon WebWare" />
<!-- ul id='main_nav'>
<li><a href="index.htm">Home</a></li>
<li><a href="http://bestautodealerwebsites.com/"
 title="Best Auto Dealer Websites .com">Automotive Dealer Website Development</a></li>
<li><a href="SoftMoon.OpenSource.htm">Free software: <acronym>PHP</acronym> and JavaScript<span class='macronym'>&trade;</span></a><ul id='sub_nav'>
<li><a href="SoftMoon.syncdir.instructions.htm#content">Folder &amp; File Synchronization Utility</a></li>
<li><a href="SoftMoon.popNewField-js_instructions.htm">Form Text-Input Auto-PopUp</a></li>
<li><a href="SoftMoon.checkEmail-js_instructions.htm#content">Form Input eMail Validation</a></li>
<li><a href="SoftMoon.validateEmailList-php_instructions.htm#content"><acronym>PHP</acronym> eMail Validation</a></li>
<li class='current'><a href="PHP_functions-instructions.php#content"><acronym>PHP</acronym> Array &amp; Other Functions</a></li>
</ul></li>
<li><a href="http://softmoon-webware.com/">Free source code editors</a></li>
<li><a href="http://softmoon-webware.com/">Modern Browser reviews</a></li>
<li><a href="http://softmoon-webware.com/">Mind Bending Games</a></li>
</ul -->

<p>[[If you  are viewing this on the PHPClasses site, the example output will not work!]]</p>
<h2><acronym>PHP</acronym>, JavaScript<span class='macronym'>&trade;</span>, <acronym>AJAX</acronym>, <acronym>XHTML</acronym>, &amp; <acronym>CSS</acronym>:
<span class='motto'>We do it <em>all</em> &mdash; We do it <em>right</em></span></h2>
</div>
<div id='content'>
<p>SoftMoon WebWare has developed some useful <acronym>PHP</acronym> and JavaScript<span class='macronym'>&trade;</span>
functions, along with a stand alone utility, that we want to share with other developers.&nbsp;
We believe in supporting the &ldquo;Open Source / Free Software Philosophy&rdquo; movement
to the greatest extent possible, in an effort to make the web a better place for all who visit and utilize it.&nbsp;
If you find any of the source code found through this page to be useful to your project, please feel free to
include them under the international terms of
<a href="http://www.gnu.org/philosophy/free-sw.html" target='page2'>The Free Software Definition</a>,
and all the software source code found on this site is released under the
<a href="http://www.gnu.org/copyleft/gpl.html" target='page2'>GNU GENERAL PUBLIC LICENSE</a> terms.</p>

<h2><acronym>PHP</acronym> Functions that should be standard</h2>
<p class='fancy'>Here&rsquo;s some functions that PHP shouldn&rsquo;t be without; but it is.&nbsp;
No problem, we just write them in PHP.&nbsp; Maybe some day they can be re-written and compiled in C++
and integrated into the PHP language itself.&nbsp; Until then, here they are:</p>


<!-- p>Click to view the <a href="PHP_functions-php_sourcecode.htm" target="_blank">highlighted sourcecode</a>, and to
download the <a href="http://softmoon-webware.com/PHP_functions.zip">.zip compressed sourcecode file</a> (5.56KB)
or the <a href="http://softmoon-webware.com/PHP_functions.tar">.tar &ldquo;compressed&rdquo; sourcecode file</a>
(16.5KB - bigger than the original).&nbsp; All example output shown is created by the actual
<acronym>PHP</acronym> code shown.</p -->

<?php include "PHP_functions.php"; ?>

<h2>swap(&amp;$V1, &nbsp;&amp;$V2)</h2>
<p>This is a basic and simple function who&rsquo;s alias is often exchange() or an 
abbreviation of.&nbsp;
We chose swap because it&rsquo;s shorter.&nbsp;
All it does is swap or exchange the values of the two variables passed to it.&nbsp;
It does not return any value.&nbsp; It offers a clean, uncluttered way of managing this need.</p>
<div class='example'>
<code>&lt;?php $a=&quot;hello&quot;;  $b=1;<br />
swap($a, $b);<br />
echo &#34;&#60;pre&#62;&#34;,var_dump($a, $b),&#34;&#60;/pre&#62;&#34;;  ?&gt;<br />
</code>
<div class='fixFirefox'><samp><?php $a="hello";  $b=1;
swap($a, $b);
echo "<pre>",var_dump($a, $b),"</pre>"; ?>
</samp></div>
</div>


<h2>LBreak_at($Llen, &nbsp;$terminator, &nbsp;$string,
&nbsp;$EOLflag=FALSE, &nbsp;$LBr=&quot;\n&quot;, &nbsp;$atEnd=FALSE)</h2>
<p>This takes a string and formats it with line breaks inserted after $terminator at most every $Llen characters.&nbsp;
If $EOLflag=TRUE the $terminator is left, otherwise it is removed at the line&rsquo;s end.&nbsp;
The examples should make it clear:</p>
<div class='example'>
<code>&#60;?php $s=&#34;Billy Anderson, Jack Phillips, James McGraw, Bobby Thomas, Howie Mandell&#34;&#59;<br />
echo &#34;&#60;pre&#62;&#34;,<br />
  LBreak_at(40, &#34;,&#34;, $s),&#34;&#60;br /&#62;\n&#34;,<br />
  LBreak_at(40, &#34;,&#34;, $s, TRUE),&#34;&#60;br /&#62;\n&#34;,<br />
  LBreak_at(40, &#34;, &#34;, $s),&#34;&#60;br /&#62;\n&#34;,<br />
  LBreak_at(40, &#34;, &#34;, $s, TRUE),&#34;&#60;br /&#62;\n&#34;,<br />
  LBreak_at(40, &#34;, &#34;, $s, FALSE, &#34;,\n&#34;),&#34;&#60;br /&#62;\n&#34;,<br />
  LBreak_at(40, &#34; &#34;, $s),&#34;&#60;br /&#62;\n&#34;,<br />
  LBreak_at(40, &#34;, &#34;, $s, FALSE, &#34;&#59;\n&#34;, TRUE),&#34;&#60;br /&#62;\n&#34;,<br />
	&#34;&#60;/pre&#62;&#34;&#59;  ?&#62;<br />
</code>
<div class='fixFirefox'><samp>
<?php $s="Billy Anderson, Jack Phillips, James McGraw, Bobby Thomas, Howie Mandell";
echo "<pre>",
	LBreak_at(40, ",", $s),"<br />\n",
	LBreak_at(40, ",", $s, TRUE),"<br />\n",
	LBreak_at(40, ", ", $s),"<br />\n",
	LBreak_at(40, ", ", $s, TRUE),"<br />\n",
	LBreak_at(40, ", ", $s, FALSE, ",\n"),"<br />\n",
	LBreak_at(40, " ", $s),"<br />\n",
	LBreak_at(40, ", ", $s, FALSE, ";\n", TRUE),"<br />\n",
 "</pre>";  ?>
</samp></div>
</div>

<a id='toXHTML'></a>
<h2>The RegulateText class</h2>
<p>This class evolved from the simple function XHTMLencode.&nbsp; The need for a class derives from the desire to
encapsulate the <code>$HTML_ENTS</code> array-table, while allowing two separate methods (functions) access to it;
best coding practices stress the rule of not polluting the global namespace.&nbsp;
The three class methods could have all been wrapped up into one (XHTMLencode) and included <code>$HTML_ENTS</code>
locally, but they are far more useful when separate.</p>

<h2 id='XHTMLencode'>XHTMLencode($S, &nbsp;$nl_to_br=TRUE, &nbsp;$allowJS=TRUE, &nbsp;$modulate_multispace='toEntities',
&nbsp;$xhtml=TRUE, &nbsp;$retain_formatting=TRUE, &nbsp;$strip_CtrlChrs=TRUE, &nbsp;$charset='ISO-8859-1',
&nbsp;$alignEnts=FALSE, &nbsp;$transform_nonstandard_Ents=FALSE,
&nbsp;$tabspacing=8, &nbsp;$hardspace=&#39;&amp;nbsp;&#39;, &nbsp;$inaTag=FALSE)</h2>
<p>First off, note that this function has <strong>many</strong> options, all of which are, well, optional.&nbsp;
You may want to only change the default value of one of the last in the list (say <code>$tabspacing</code>);
this can get hairy trying to keep up with all the options, their order in the list, their default values,
and what default <strong>your</strong> code is modifying.&nbsp;
Therefore, this function is ready to accept options in two different formats or &ldquo;ways&rdquo;.
You can pass them in order, as in the function definition; or you can pass an array as the second value,
with the keys of the array corresponding to the options,
and the values of said keys becoming the values of the options.&nbsp;
The code below exemplifies these two optional formats:</p>
<div class='example'><code>
$encodedString=RegulateText::XHTMLencode(<br />
&nbsp; $partiallyEncodedString, FALSE, TRUE, &#39;toEntities&#39;, TRUE, TRUE, TRUE, &#39;ISO-8859-1&#39;, FALSE, FALSE, 4);<br />
<br />
$encodedString=RegulateText::XHTMLencode(<br />
&nbsp; $partiallyEncodedString, array('nl_to_br' =&#62; FALSE, 'tabspacing' =&#62; 4));<br />
</code></div>
<p>This is similar to the pre-existing
<a href='http://www.php.net/manual/en/function.htmlentities.php/' target='page2'>htmlentities()</a> function,
but different.&nbsp;
It encodes all stray entities, but preserves valid (X)HTML markup including already encoded entities as well as
well formed tags.&nbsp;
It can also intelligently apply a &#60;br&#62; or a &#60;br&nbsp;/&#62; before any &ldquo;new&nbsp;line&rdquo; characters
in the text, taking into consideration whether the line break is inside an <acronym>HTML</acronym> tag, or between
opening and closing &#60;pre&#62; &#60;/pre&#62; tags.&nbsp;
It can also make spacing in text &lsquo;stick&rsquo; using the same logic.&nbsp; More on that below.&nbsp;
This allows your data provided by knowledgeable users to include markup,
but makes sure other data is ready for validate-able (X)HTML pages.&nbsp;
Note it does not fully validate the (X)HTML markup, it only makes sure it is well formed;
i.e. only &ldquo;legal&rdquo; entities and tags will be preserved, but it does <strong>not</strong>
take into consideration whether the tag attributes are legal, only that they are &ldquo;well&nbsp;formed&rdquo;.&nbsp;
It also takes <strong>no consideration</strong> of whether a tag is opened and closed properly,
or whether a tag may be nested inside another.</p>
<p>Some tags were left out, as it usually makes no sense to allow &lt;head&gt; or &lt;frame&gt; tags in data output,
nor does it make sense to script forms and their controls.&nbsp;
Note the awesome power the &lt;object&gt; and &lt;applet&gt; tags have,
and allowing them to be scripted by data requires faith in your data.&nbsp;
In fact, this function opens up the data to allowing JavaScript<span class='macronym'>&trade;</span>
to be embedded in web pages via data.&nbsp; Care should be taken on how this is implemented.&nbsp;
Set the <code>$allowJS</code> flag to <code>FALSE</code> if you are processing user input from a
form on the World Wide Web to be posted on your public pages for security reasons;
likewise, trim back the allowed tags to your liking.</p>
<p>You may want to custom-edit the allowed (X)HTML tags for your specific application by either
hardcoding your choices into the function, or better yet, by passing them to the function.&nbsp;
The latter is accomplished only by using the &ldquo;array-based options&rdquo; format when calling this
class method (function).&nbsp; For example:<br />
<code>RegulateText::XHTMLencode($S, array(&#39;HTML_TAGS&#39; =&gt; array(&#39;a&#39;, &#39;b&#39;, &#39;i&#39;)))</code><br />
allows only anchor, bold, and italics tags.&nbsp; Because <code>$HTML_TAGS</code> is a static local variable,
any change you make to the list of acceptable tags persists until the entire running script has ended.&nbsp;
That means if you call it several times to produce a single web page, you only need to pass your
custom list of tags the first time.&nbsp;  If you need to change the list again, simply pass a new array
and it will persist.</p>
<p>By default, HTML browsers collapse multiple spaces and line breaks into a single space.&nbsp;
By default, this function converts multiple spaces to a
&#38;nbsp&#59; &#38;nbsp&#59; &#38;nbsp&#59; &#38;nbsp&#59; &#38;nbsp&#59; format;
and any space following a line break is also converted into a &#38;nbsp&#59;.&nbsp;
[You may choose any entity you want besides &amp;nbsp; with the <code>$hardspace</code> option]&nbsp;
If you set <code>$modulate_multispace</code> to <code>TRUE</code>, multiple spaces will be collapsed to one.&nbsp;
Logically, if you set <code>$modulate_multispace</code> to <code>FALSE</code>,
multiple spaces will be left &ldquo;as is&rdquo;.&nbsp;
When <code>$tabspacing</code> is a positive number, any tab characters are likewise expanded in a
format as multiple spaces; the number of spaces being equal to <code>$tabspacing</code>.</p>
<p>Usually, you want to leave <code>$inaTag=FALSE</code>; this is used internally,
but you may too if you have a reason.&nbsp;
If <code>$xhtml=FALSE</code>, a much less stringent format is allowed in HTML tags.&nbsp;
If <code>$strip_CtrlChrs=TRUE</code>, all control characters [<acronym>ASCII</acronym> 0-31 (00-1F in hexadecimal)]
will be removed, with the exception of carriage returns and tabs when <code>$retain_formatting=TRUE</code>.&nbsp;
Note, though, that if <code>$strip_CtrlChrs=FALSE</code> carriage returns and tabs will remain even if
<code>$retain_formatting=FALSE</code>.&nbsp;
You may pass your own hardspace, maybe <code>&amp;#160;</code> as that is the same as <code>&amp;nbsp;</code>.&nbsp;
And the <code>$charset</code> is simply passed through to <acronym>PHP</acronym>'s
<a href='http://www.php.net/manual/en/function.htmlentities.php/' target='page2'>htmlentities()</a> function.</p>
<p>The options <code>$alignEnts</code> and <code>$transform_nonstandard_Ents</code> simply call the
sibling methods of the <code>RegulateText</code> class.&nbsp; By default these auxiliary methods are not called;
pass in the values you want passed through.&nbsp; More on those methods below...</p>

<h2>XML_entitiesAlign($S, &nbsp;$alignTo=&#39;numeric&#39;, &nbsp;$nonstandard_Ents=&#39;numeric&#39;)</h2>
<p>This will convert all entities to either numeric format (when <code>$alignTo=&#39;numeric&#39;</code>),
or (when <code>$alignTo=&#39;mnemonic&#39;</code> etc...) to textual format if such exists for that entity.
It will avoid converting nonstandard Entities to &#39;mnemonic&#39; if you specify them separately as
&#39;numeric&#39;; but as the inverse is illogical, it will not convert nonstandard Entities to &#39;mnemonic&#39;
if you specify <code>$alignTo=&#39;numeric&#39;</code>.&nbsp;
If you pass an array in as <code>$nonstandard_Ents</code> (instead of the default string-based-flag format)
then the array will be used as the Entity Table (for use with custom XML docs), instead of the default
<code>$HTML_ENTS</code>.</p>

<h2>transform_nonstandard_entities($S, &nbsp;$flag=&#39;numeric&#39;)</h2>
<p>This straightforward function simply takes your string and transforms the three &ldquo;nonstandard&rdquo; Entities
(&amp;apos; [&#39;] &nbsp;&amp;lsaquo; [&lsaquo;] &nbsp;&amp;rsaquo; [&rsaquo;])
either to/from &#39;numeric&#39; to/from &#39;mnemonic&#39;.&nbsp;
It will transform both decimal and hexadecimal numericals to mnemonic, but only from mnemonic to decimal.&nbsp;
Technically, &amp;apos; is only allowed in <acronym>XHTML</acronym> documents, not in <acronym>HTML</acronym>.&nbsp;
The other two are widely supported by modern browsers, yet they are still considered &ldquo;nonstandard&rdquo;
and should therefore be converted to numeric format for proper validation in many cases.&nbsp;
For readability purposes though, to &#39;mnemonic&#39; was included as a bonus.</p>
<!-- p>This class (RegulateText) and its methods are all best exemplified off-page with a working model.&nbsp;
Here&rsquo;s the <a href="test_XHTMLencode-php_sourcecode.htm" target="_blank">highlighted demo sourcecode</a>,
and the <a href="test_XHTMLencode.php" target="_blank">working demo.</a></p -->

<h2>array_is_similar($A1, &nbsp;$A2, &nbsp;&amp;$Adif=&quot;&quot;)</h2>
<p>This function compares the two arrays passed to it, and returns TRUE if they have all the same values,
FALSE if not.&nbsp; The keys do NOT have to match in any way.&nbsp;
The values that are different can be passed back in the optional third parameter,
but due to the way array_merge() works, this is not completely reliable with non-numeric indexes.</p>

<h2>array_not_similar($A1, &nbsp;$A2)</h2>
<p>This function returns an array of all the values in the two given arrays that are unique to one array in the pair,
or NULL if they have all the same values.&nbsp; The keys do NOT have to match in any way.&nbsp;
Due to the way array_merge() works, this is not completely reliable with non-numeric indexes.</p>

<h2>array_equals(&amp;$A1, &nbsp;&amp;$A2, &nbsp;$IdentFLAG=FALSE)</h2>
<p>This function looks deep into both arrays passed into it and returns TRUE if they have all the
same keys with the same values, and FALSE otherwise.&nbsp; If you pass TRUE as the third value ($IdentFLAG),
the arrays will be modified so all EQUAL values are set to NULL, leaving the rest identified.</p>

<h2>casei_in_array($VALUE, &nbsp;$A)</h2>
<p>If the string passed in $VALUE is a case-insensitive match to one of the strings in the array $A,
this function returns the string from the array that matched or TRUE if the string evaluates to FALSE,
or FALSE if no match is found.</p>

<h2>array_ikey_exists($KEY, &nbsp;$A)</h2>
<p>If the string passed in $KEY is a case-insensitive match to one of the keys in the array $A,
this function returns the key from the array that matched, or FALSE if no match is found.</p>


<h2>preg_key_grep($A, &nbsp;$preg, &nbsp;$KeepKey=FALSE)</h2>
<p>This function is similar to preg_grep(), except it does a Perl-compatible Regular Expression check
on the keys of the array passed to it, then returns an array of those values whose keys matched the check.&nbsp;
The array returned is numerically indexed, unless you pass TRUE as the third value ($KeepKey) which
preserves the original keys.</p>

<h2>is_iterateable($var)</h2>
<p>This function returns TRUE if the variable $var passed to it can be iterated using
<code>foreach ($var as $arrayValue)</code> or FALSE if not.&nbsp;
Note it is defaulted to work only with PHP 5.3 and above, but you can comment that part out if needed.</p>

<h2>array_junction($new_keys, &nbsp;$A1, &nbsp;$A2 [, $A3, ... $A10, ...&nbsp;$¿allKeys=FALSE])</h2>
<p>This takes any number of arrays passed to it (minimum of 3); the first is the keys for the data, the rest are data.&nbsp;
It creates one new array combining the others.&nbsp; It is the complement of the next function, array_subkey().&nbsp;
If the last value passed ($¿allKeys) is passed a boolean TRUE (this <em>must</em> be boolean),
all keys in all arrays will be used to create the new array;
otherwise the default is that the new array only contains keys found in all given data arrays.&nbsp;
A couple examples should make all this clear:</p>
<div class='example'>
<code>&#60;?php<br />
$arr1=array('first' =&#62; &#34;Jimmy&#34;, 'second' =&#62; &#34;Jonny&#34;, 'third' =&#62; &#34;Roger&#34;, 'forth' =&#62; &#34;Tim&#34;)&#59;<br />
$arr2=array('first' =&#62; &#34;Hendrix&#34;, 'second' =&#62; &#34;Cash&#34;, 'third' =&#62; &#34;Waters&#34;, 'fifth' =&#62; &#34;GaGa&#34;)&#59;<br />
$arr3=array('first' =&#62; &#34;guitar&#34;, 'second' =&#62; &#34;guitar&#34;, 'third' =&#62; &#34;bass&#34;, 'sixth' =&#62; &#34;drums&#34;)&#59;<br />
$keys=array(&#34;first-name&#34;, &#34;last-name&#34;, &#34;instrument&#34;)&#59;<br />
echo &#34;&#60;pre&#62;&#34;,var_dump(<br />
	array_multijunction($keys, $arr1, $arr2, $arr3),<br />
	"====================",<br />
	array_multijunction($keys, $arr1, $arr2, $arr3, TRUE) ),<br />
	&#34;&#60;/pre&#62;&#34;&#59;  ?&#62;<br />
</code>
<div class='fixFirefox'><samp><?php
$arr1=array('first' => "Jimmy", 'second' => "Jonny", 'third' => "Roger", 'forth' => "Tim");
$arr2=array('first' => "Hendrix", 'second' => "Cash", 'third' => "Waters", 'fifth' => "GaGa");
$arr3=array('first' => "guitar", 'second' => "guitar", 'third' => "bass", 'sixth' => "drums");
$keys=array("first-name", "last-name", "instrument");
echo "<pre>",var_dump(
	array_multijunction($keys, $arr1, $arr2, $arr3),
	"=====================",
	array_multijunction($keys, $arr1, $arr2, $arr3, TRUE) ),
	"</pre>";
?>
</samp></div>
</div>

<h2>array_subkey($A, &nbsp;$indxLevel, &nbsp;$IDkey, &nbsp;$KeepKey=FALSE)<br />
array_subkey&#164;5&middot;3($A, &nbsp;$indxLevel, &nbsp;$IDkey, &nbsp;$KeepTree=FALSE)</h2>
<p>These two sibling functions are the complement of array_multijunction().&nbsp;
The first, array_subkey(), is the little brother of the extraordinary array_subkey&#164;5&middot;3(),
but it still puts a simple-to-use tool in your hand that is very powerful.&nbsp;
The most simple way to state its use is to say it returns a column of data from a row-based array.&nbsp;
array_subkey&#164;5&middot;3() can return many columns at once, re-key them, and even dig into class-objects;
I call it the Jedi-powered Cuisinart of array functions :)</p>
<p>array_subkey&#164;5&middot;3() is best suited for <acronym>PHP</acronym> 5.3 and up,
but it can be adapted easily (see the internal comments in the sourcecode) to earlier versions.&nbsp;
With <acronym>PHP</acronym> 5.3, you can pass closures as parameters defining what &ldquo;keys&rdquo; to return
(in fact the closure-function can do anything you need it to do!).&nbsp;
With versions of PHP that support Object Oriented Class Methods, you can pass instances of your class
with a method called &#147;filter&#148; that works the same as passing a closure in PHP 5.3.&nbsp;
With earlier versions, you pass a string which refers to a function named in your code;
trouble begins when a key in your array has the same string-name as a function in your code.&nbsp;
If you can guarantee to avoid this by either controlling the key names,
or verifying ahead that there is no conflict, then array_subkey&#164;5&middot;3() will work with
<acronym>PHP</acronym> without Classes or Closures.</p>
<p>Both are designed to work with arrays of arrays of arrays.....
as well as arrays of class-objects with properties that are arrays or class-objects ......&nbsp;
With array_subkey() you have simple access to a key or keys at your choice of &ldquo;level&rdquo;
in the array passed into.&nbsp; Note that levels start with (1), not (0).&nbsp;
Any number to the zero power is the singularity; that is to say an array at level (0) is the complete array.&nbsp;
They both allow you to &ldquo;pull out&rdquo; the data you need buried deep in a multi-dimensional array.&nbsp;
With array_subkey&#164;5&middot;3(), you can filter through every dimension to pinpoint and retrieve
exactly what you need at multiple levels, if you set up $IDkey with the right filter.&nbsp;
Again, this is all best explained with examples.&nbsp; Below are examples using array_subkey().&nbsp;
Examples of array_subkey&#164;5&middot;3() are off-page;
please see the specific demo files packaged in this package
(but remember you must run them on a system with PHP 5.3 or greater).&nbsp;
</p>
<div class='example'>
<code>&#60;?php $arr=array(<br />
  'dancing_singer' =&#62; array('firstname' =&#62; &#34;Donnie&#34;, 'lastname' =&#62; &#34;Osman&#34;, 'job' =&#62; &#34;glitter-glammer&#34;),<br />
  'actor_director' =&#62; array('firstname' =&#62; &#34;Ronnie&#34;, 'lastname' =&#62; &#34;Howard&#34;, 'job' =&#62; &#34;societal advisoure&#34;),<br />
  'guitarist_songwriter' =&#62; array('firstname' =&#62; &#34;George&#34;, 'lastname' =&#62; &#34;Harrison&#34;, 'job' =&#62; &#34;musician extraordinaire&#34;))&#59;<br />
echo &#34;&#60;pre&#62;&#34;,var_dump(<br />
  array_subkey($arr, 2, &#34;firstname&#34;),<br />
  array_subkey($arr, 2, &#34;firstname&#34;, TRUE),<br />
  array_subkey($arr, 2, array(&#34;firstname&#34;, &#34;job&#34;)),<br />
  array_subkey($arr, 2, array(&#34;firstname&#34;, &#34;job&#34;), TRUE)),<br />
	&#34;&#60;/pre&#62;&#34;&#59;<br />
?&#62;<br />
</code>
<div class='fixFirefox'><samp><?php $arr=array(
	'dancing_singer' => array('firstname' => "Donnie", 'lastname' => "Osman", 'job' => "glitter-glammer"),
	'actor_director' => array('firstname' => "Ronnie", 'lastname' => "Howard", 'job' => "societal advisoure"),
	'guitarist_songwriter' => array('firstname' => "George", 'lastname' => "Harrison", 'job' => "musician extrodinare"));
echo "<pre>",var_dump(
	array_subkey($arr, 2, "firstname"),
	array_subkey($arr, 2, "firstname", TRUE),
	array_subkey($arr, 2, array("firstname", "job")),
	array_subkey($arr, 2, array("firstname", "job"), TRUE)),
	"</pre>";
?>
</samp></div>
</div>


</div>
<div id='footer'>
<p>All content Copyright &copy; 2010 by SoftMoon WebWare,
all rights reserved, unless otherwise specifically noted.<br />
&ldquo;JavaScript<span class='macronym'>&trade;</span>&rdquo; is a trademark of Sun Microsystems.</p>
</div>
</body>
</html>