Class: Bs_HtmlUtil
Source Location: /core/html/Bs_HtmlUtil.class.php
Bs_Object
|
--Bs_HtmlUtil
This static class provides many useful html methods.
Author(s):
Version:
- 4.0.$Id: Bs_HtmlUtil.class.php,v 1.3 2003/10/29 17:48:38 andrej Exp $
Copyright:
|
|
Inherited Variables
|
Inherited Methods
|
Class Details
Class Methods
constructor Bs_HtmlUtil [line 26]
Bs_HtmlUtil Bs_HtmlUtil(
)
|
|
constructor.
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:
Parameters:
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 "cool""> <input type="hidden" name="bar" value="foo > bar"> $data = array('foo'=>array()); $html = $Bs_HtmlUtil->arrayToHiddenFormFields($data); the output is: empty string ''.
Tags:
Parameters:
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:
Parameters:
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:
Parameters:
method charToHtml [line 41]
string charToHtml(
[string
$param = ''], [bool
$reverse = FALSE])
|
|
Convert a real string into an 'html' string, eg convert AB to AB 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:
Parameters:
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 '&' '"' (double quote) becomes '"' when ENT_NOQUOTES is not set. ''' (single quote) becomes ''' only when ENT_QUOTES is set. '<' (less than) becomes '<' '>' (greater than) becomes '>' '\n' (line feed) becomes ' ' '\r' (carriage return) becomes ' '
Tags:
Parameters:
method filterForHtmlUndo [line 124]
void filterForHtmlUndo(
mixed
$param, [mixed
$quoteTrans = ENT_COMPAT])
|
|
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:
Parameters:
method htmlEntities2 [line 398]
void htmlEntities2(
mixed
$string)
|
|
synonyme of htmlEntitiesUndo().
Tags:
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:
Parameters:
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:
Parameters:
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:
Parameters:
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:
|
|