| core_html

# Class: Bs_HtmlUtil Source Location: /core/html/Bs_HtmlUtil.class.php
### Class Overview
    Bs_Object
       |
       --Bs_HtmlUtil
This static class provides many useful html methods. #### Author(s): andrej arn <at blueshoes dot org> #### Version: 4.0.$Id: Bs_HtmlUtil.class.php,v 1.3 2003/10/29 17:48:38 andrej Exp $ #### Copyright: blueshoes.org | ### Methods Bs_HtmlUtil arrayToFormFieldNames arrayToHiddenFormFields arrayToHtmlSelect arrayToJsArray charToHtml filterForHtml filterForHtmlUndo filterForJavaScript htmlEntities2 htmlEntitiesUndo jsAlert parseAttrStr parseStyleStr
### Inherited Variables | ### Inherited Methods #### Class: Bs_Object Bs_Object::Bs_Object() Bs_Object::getErrors() Basic error handling: Get *all* errors as string array from the global Bs_Error-error stack. Bs_Object::getLastError() Basic error handling: Get last error string from the global Bs_Error-error stack. Bs_Object::getLastErrors() Basic error handling: Get last errors string array from the global Bs_Error-error stack sinc last call of getLastErrors(). Bs_Object::persist() Persists this object by serializing it and saving it to a file with unique name. Bs_Object::setError() Basic error handling: Push an error string on the global Bs_Error-error stack. Bs_Object::toHtml() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::toString() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::unpersist() Fetches an object that was persisted with persist()
### Class Details [line 20] This static class provides many useful html methods. no dependencies here. #### Tags:
pattern: | singleton: (pseudostatic) static
access: | public
version: | 4.0.$Id: Bs_HtmlUtil.class.php,v 1.3 2003/10/29 17:48:38 andrej Exp $
copyright: | blueshoes.org
author: | andrej arn <at blueshoes dot org>
[ Top ] ### Class Methods ### constructor Bs_HtmlUtil [line 26]
`Bs_HtmlUtil Bs_HtmlUtil( )`
constructor. [ Top ] ### method arrayToFormFieldNames [line 374]
`array arrayToFormFieldNames( array $data, [string $varName = ''])`
takes an array and returns the keys as they would be used for form field names. the given $data may be a boxed array, it will be looped recursively. WARNING: make sure it has no recursive references! this method calls itself recursively if needed. examples: $data = array('foo'=>'bar', 'hello'=>'world'); $html = $Bs_HtmlUtil->arrayToFormFieldNames($data); the output is: array('foo', 'hello'); $data = array('foo'=>array('foo'=>'bar', 'hello'=>'world')); $html = $Bs_HtmlUtil->arrayToHiddenFormFields($data); the output is: array('foo[foo]', 'foo[hello]'); #### Tags:
return: | (hash, empty array if no data.)
see: | $this->arrayToHiddenFormFields()
since: | bs4.3
access: | public
#### Parameters:
array | $data |
string | $varName | (not needed for most cases, see examples above.)
[ Top ] ### method arrayToHiddenFormFields [line 321]
`string arrayToHiddenFormFields( array $data, [string $varName = ''])`
generates hidden form fields from the given array. the given $data may be a boxed array, it will be looped recursively. WARNING: make sure it has no recursive references! this method calls itself recursively if needed. examples: $data = array('foo'=>'bar', 'hello'=>'world'); $html = $Bs_HtmlUtil->arrayToHiddenFormFields($data); the output is: <input type="hidden" name="foo" value="bar"> <input type="hidden" name="hello" value="world"> $data = array('foo'=>array('foo'=>'bar', 'hello'=>'world')); $html = $Bs_HtmlUtil->arrayToHiddenFormFields($data); the output is: <input type="hidden" name="foo[foo]" value="bar"> <input type="hidden" name="foo[hello]" value="world"> $data = array('foo'=>"sam's pizzaland is \"cool\"", 'bar'=>'foo > bar'); $html = $Bs_HtmlUtil->arrayToHiddenFormFields($data); the output is: <input type="hidden" name="foo" value="sam's pizzaland is &quot;cool&quot;"> <input type="hidden" name="bar" value="foo &gt; bar"> $data = array('foo'=>array()); $html = $Bs_HtmlUtil->arrayToHiddenFormFields($data); the output is: empty string ''. #### Tags:
return: | (html, or empty string if no data.)
see: | $this->arrayToFormFieldNames()
since: | bs4.3
access: | public
#### Parameters:
array | $data |
string | $varName | (not needed for most cases, see examples above.)
[ Top ] ### method arrayToHtmlSelect [line 262]
`string arrayToHtmlSelect( array $myArray, [mixed $selected = ''])`
Takes any array and returns a string with the options to seed an html select field. Depending if the array is a hash- or a normal 'zerobased'-array the result looks defferent. Example I: Normal 'zerobased'-array $myArray = array('red', 'green', 'blue'); $selected = 'green'; arrayToHtmlSelect($myArray, $selected); <option value="red">red</option> <option value="green" selected>green</option> <option value="blue">blue</option> Example II: hash-array $myArray = array('ch'=>'Switzerland', 'de'=>'Germany', 'at'=>'Austria'); $selected = array('ch', 'at'); arrayToHtmlSelect($myArray, $selected); <option value="ch" selected>Switzerland</option> <option value="de">Germany</option> <option value="at" selected>Austria</option> NOTE: If you try to use an array as param $selected, make sure your <select has the option 'multiple' and a 'size' that is >1. #### Tags:
return: | returns option part of html-select string.
#### Parameters:
array | $myArray | can be a normal array or a hash array.
mixed | $selected | a string with one key, or an array with more, see examples.
[ Top ] ### method arrayToJsArray [line 204]
`string arrayToJsArray( array $array, [string $nameOfJsArray = 'myArray'], [bool $forceVector = FALSE], [bool $makeVarGlobal = FALSE], [bool $firstCall = TRUE])`
takes a php array and creates a js array definition that can be spitted out. method calls itself recursively. examples: $array = array('foo'=>'bar', 'hello'=>'world'); arrayToJsArray($array, 'x'); output: var x = new Array(); x['foo'] = "bar"; x['hello'] = "world"; arrayToJsArray($array, 'x', TRUE); output: var x = new Array(); x[0] = "bar"; x[1] = "world"; $array = array('foo'=>'bar', 'a'=>array('foo'=>'bar', 'hello'=>'world')); arrayToJsArray($array, 'x'); output: var x = new Array(); x['foo'] = \"bar\"; x['a'] = new Array(); x['a']['foo'] = \"bar\"; x['a']['hello'] = \"world\"; x['c'] = \"d\"; arrayToJsArray($array, 'x', TRUE); output: var x = new Array(); x[0] = \"bar\"; x[1] = new Array(); x[1][0] = \"bar\"; x[1][1] = \"world\"; x[2] = \"d\"; #### Tags:
access: | public
#### Parameters:
array | $array |
string | $nameOfJsArray | (default is 'myArray')
bool | $forceVector | (default is FALSE, this option exists since bs4.3. see examples.)
bool | $makeVarGlobal | (if the var should be global, means without the "var" statement. default is FALSE. added in bs4.3.)
bool | $firstCall | (used internally only! do not touch this!)
[ Top ] ### method charToHtml [line 41]
`string charToHtml( [string $param = ''], [bool $reverse = FALSE])`
Convert a real string into an 'html' string, eg convert AB to &#65;&#66; this function is useful to 'decrypt' email addresses so email spiders won't detect them, hopefully. NOTE: not all characters will be converted, only 0-9 a-z A-Z and @ will be done. #### Tags:
return: | the converted string.
#### Parameters:
string | $param | the string you want to convert from plaintext to html.
bool | $reverse | (optional, default FALSE)do reverse.
[ Top ] ### method filterForHtml [line 116]
`string filterForHtml( string $param, [mixed $quoteTrans = ENT_COMPAT])`
This function is useful in preventing user-supplied text from containing HTML markup, such as in a message board or guest book application. The optional second argument, quoteTrans, tells the function what to do with single and double quote characters. Otherwise something like this may occur: <input type="text" name="blah" value="this is a "buggy" default value"> Older browsers will fail and only display "this is a " as default value. (IE5.5 can handle this in textarea fields. but... please use this function.) The default mode, ENT_COMPAT, is the backwards compatible mode which only translates the double-quote character and leaves the single-quote untranslated. If ENT_QUOTES is set, both single and double quotes are translated and if ENT_NOQUOTES is set neither single nor double quotes are translated. The only difference to PHP's built in function htmlspecialchars() is that '\n' (line feed) and '\r' (carriage return) are also translated. Tranformation characters: '&' (ampersand) becomes '&amp;' '"' (double quote) becomes '&quot;' when ENT_NOQUOTES is not set. ''' (single quote) becomes '&#039;' only when ENT_QUOTES is set. '<' (less than) becomes '&lt;' '>' (greater than) becomes '&gt;' '\n' (line feed) becomes '&#10;' '\r' (carriage return) becomes '&#13;' #### Tags:
return: | filtered string
see: | Bs_HtmlUtil::filterForJavaScript()
#### Parameters:
string | $param | string to be filtered
[ Top ] ### method filterForHtmlUndo [line 124]
`void filterForHtmlUndo( mixed $param, [mixed $quoteTrans = ENT_COMPAT])`
[ Top ] ### method filterForJavaScript [line 79]
`string filterForJavaScript( string $param)`
Converts an ordinary string to a client-side JavaScript friendly version to be written out on the client webpage if you want to write out javascript code with javascript strings, use this function for the values of the js strings. #### Tags:
return: | filtered string
see: | Bs_HtmlUtil::filterForHtml()
#### Parameters:
string | $param | string to be filtered
[ Top ] ### method htmlEntities2 [line 398]
`void htmlEntities2( mixed $string)`
synonyme of htmlEntitiesUndo(). #### Tags:
deprecated: |
see: | Bs_HtmlUtil::htmlEntitiesUndo()
[ Top ] ### method htmlEntitiesUndo [line 411]
`string htmlEntitiesUndo( mixed $string, string $strong)`
Convert all HTML entities to applicable characters. This is the reversed function of php's htmlentities(). i bet it will be implemented in php soon. #### Tags:
todo: | check from time to time if this method is implemented in php now. php4.3: not yet. --andrej
see: | php's get_html_translation_table(), htmlspecialchars() and htmlentities().
#### Parameters:
string | $strong |
[ Top ] ### method jsAlert [line 147]
`string jsAlert( string $value)`
returns $value as a javascript popup. sometimes echo is not suitable cause you're somewhere in the middle of the output, or you're in a frame, or whatever that makes it difficult to find your debug echo/vardump output. the function does not output anything itself. uses $this->filterForJavaScript(). #### Tags:
return: | a javascript string
see: | $this->filterForJavaScript()
access: | public
#### Parameters:
string | $value |
[ Top ] ### method parseAttrStr [line 468]
`&array &parseAttrStr( string &$attrStr)`
Parse a attr string of a format like below to a hash array Separator assumed: For the elements ' ', for the key/value pair '=' E.g. If following is given as input : ALIGN = 'right' value='' bgcolor="blue" selected You will get an hash array as follows: array('align'=>'right', 'value'=>'', 'bgcolor'=>'blue', 'selected'=>NULL) #### Tags:
todo: | It works, but not very efficent.
#### Parameters:
string | &$attrStr |
[ Top ] ### method parseStyleStr [line 432]
`&array &parseStyleStr( string &$styleStr)`
Parse a style string of a format like below to a hash array Separator assumed: For the elements ';', for the key/value pair ':' E.g. If following is given as input : font-family: arial, helvetica; font-size: 10pt; color: #000000; key: ; key2; ; You will get an hash array as follows: array('font-family'=>'arial, helvetica', 'font-size'=>'10pt', 'color'=>'#000000', 'key'=>' ', 'key2'=>NULL) #### Parameters:
string | &$styleStr |
[ Top ] Documentation generated on Mon, 29 Dec 2003 21:11:09 +0100 by phpDocumentor 1.2.3