\SimpleHTML

A class to treat an HTML document as a PHP object

PHP version 5

Summary

Methods
Properties
Constants
__call()
__toString()
a()
addChild()
aimg()
appendText()
checkbox()
css()
file()
form()
hidden()
img()
input()
js()
label()
password()
radio()
reset()
selectize()
submit()
tableize()
text()
detectProperMimeType()
sendMimeType()
factory()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__call()

__call(string $element, array $arguments) : \SimpleHTML

The magic method that is called when an element that doesn't have its own method is added. Creates and adds objects to the node tree based on supplied arguments.

Parameters

string $element

Element name

array $arguments

Element attributes

Returns

\SimpleHTML

Newly created node

__toString()

__toString() : string

Converts the object into a valid XHTML 1.0 Strict document with indenting.

If user agent does not accept application/xhtml+xml, the XML prolog is removed. If an html fragment (i.e. <html> is not root), DOCTYPE and XML prolog are not added.

Returns

string —

XHTML document

a()

a(mixed $inner, string $href) : \SimpleHTML

Create an <a> element

If a single string argument is given, it is the href attribute instead. If an argument is an array, they are attributes.

Parameters

mixed $inner

Link contents

string $href

Destination

Returns

\SimpleHTML

Newly created <a> element

addChild()

addChild(mixed $node, string $contents) : \SimpleHTML

Overloaded SimpleXMLElement function to allow adding an existing object

NOTE: A copy of $node is added, not the original

Parameters

mixed $node

Node to be added

string $contents

Value of node

Returns

\SimpleHTML

Newly created node

aimg()

aimg(string $href, string $src, string $alt, string $title) : \SimpleHTML

Create an <img> inside an <a>

Parameters

string $href

Link destination

string $src

Image source

string $alt

Alternate text

string $title

Title text

Returns

\SimpleHTML

Newly created <a> element

appendText()

appendText(string $text) : \SimpleHTML

Appends text to the contents of an element

Parameters

string $text

Text to append

Returns

\SimpleHTML

Updated node

checkbox()

checkbox(string $name, string $value, string $id, boolean $checked, array $extra) : \SimpleHTML

Create a checkbox

Parameters

string $name

Name value

string $value

Default value

string $id

Id value

boolean $checked

Checked

array $extra

Extra attributes

Returns

\SimpleHTML

Newly created <input> element

css()

css(mixed $href, string $title) : \SimpleHTML

Create a <link> element for a CSS file

If the first argument is an array, a <link> is created for each one If not provided, the currently running script name is used

Parameters

mixed $href

CSS file(s) to link

string $title

Title of link

Returns

\SimpleHTML

Last created <link> element

file()

file(string $name, string $value, string $id, array $extra) : \SimpleHTML

Create a file upload input

Parameters

string $name

Name value

string $value

Default value

string $id

Id value

array $extra

Extra attributes

Returns

\SimpleHTML

Newly created <input> element

form()

form(string $method, string $action, array $extra) : \SimpleHTML

Create a <form> element

Parameters

string $method

Form submission method

string $action

Form submission destination

array $extra

Extra attributes

Returns

\SimpleHTML

Newly created <&gt> element

hidden()

hidden(string $name, string $value, string $id, array $extra) : \SimpleHTML

Create a hidden input

Parameters

string $name

Name value

string $value

Default value

string $id

Id value

array $extra

Extra attributes

Returns

\SimpleHTML

Newly created <input> element

img()

img(string $src, string $alt, string $title) : \SimpleHTML

Create an <img> element

If the first argument is an array, they are attributes.

Parameters

string $src

Image source

string $alt

Alternate text

string $title

Title text

Returns

\SimpleHTML

Newly created <img> element

input()

input(string $name, string $value, string $id, string $type, array $extra) : \SimpleHTML

Create an <input> element

If the first argument is an array, they are attributes.

Parameters

string $name

Name value

string $value

Default value

string $id

Id value

string $type

Input type

array $extra

Extra attributes

Returns

\SimpleHTML

Newly created <input> element

js()

js(mixed $src) : \SimpleHTML

Create a <script> element for a Javascript file

If the first argument is an array, a <script> is created for each one If not provided, the currently running script name is used

Parameters

mixed $src

Javascript file(s) to link

Returns

\SimpleHTML

Last created <script> element

label()

label(string $contents, string $for) : \SimpleHTML

Create a <label> element

If an argument is an array, they are attributes.

Parameters

string $contents

Label contents

string $for

For value

Returns

\SimpleHTML

Newly created <label> element

password()

password(string $name, string $value, string $id, array $extra) : \SimpleHTML

Create a password input

Parameters

string $name

Name value

string $value

Default value

string $id

Id value

array $extra

Extra attributes

Returns

\SimpleHTML

Newly created <input> element

radio()

radio(string $name, string $value, string $id, boolean $checked, array $extra) : \SimpleHTML

Create a radio input

Parameters

string $name

Name value

string $value

Default value

string $id

Id value

boolean $checked

Checked

array $extra

Extra attributes

Returns

\SimpleHTML

Newly created <input> element

reset()

reset(string $name, string $value, string $id, array $extra) : \SimpleHTML

Create a reset input

Parameters

string $name

Name value

string $value

Default value

string $id

Id value

array $extra

Extra attributes

Returns

\SimpleHTML

Newly created <input> element

selectize()

selectize(array $options, array $selected, array $name, string $id, array $extra) : \SimpleHTML

Turn an array into a <select> element

Each row of the array will correspond to an <option> element. If an array element is also an array, the first two elements are used as the contents and value. Otherwise it is used as the both.

Parameters

array $options

Select options

array $selected

Option to default as selected

array $name

Name attribute

string $id

Id attribute

array $extra

Extra attributes

Returns

\SimpleHTML

Newly created <select> element

submit()

submit(string $name, string $value, string $id, array $extra) : \SimpleHTML

Create a submit input

Parameters

string $name

Name value

string $value

Default value

string $id

Id value

array $extra

Extra attributes

Returns

\SimpleHTML

Newly created <input> element

tableize()

tableize(array $body, array $head, array $foot, string $caption) : \SimpleHTML

Turn an array into a <table> element

Each row of the array will correspond to a <tr> element. Each array element will correspond to a <td> element. If the array element is an array, the first two elements are used as the contents and attributes. Otherwise it is used as the contents

Parameters

array $body

Table contents

array $head

Header row

array $foot

Footer data

string $caption

Table caption

Returns

\SimpleHTML

Newly created <table> element

text()

text(string $name, string $value, string $id, array $extra) : \SimpleHTML

Create a text input

Parameters

string $name

Name value

string $value

Default value

string $id

Id value

array $extra

Extra attributes

Returns

\SimpleHTML

Newly created <input> element

detectProperMimeType()

detectProperMimeType() : string

See if the requester supports the XHTML mime type

Checks the HTTP_ACCEPT header and if the User Agent prefers it the MIME type application/xhtml+xml is returned instead of text/html

Returns

string —

The appropriate MIME type

sendMimeType()

sendMimeType()

Set the Content Type header to the appropriate MIME type

factory()

factory(string $element, mixed $a, mixed $b) : \SimpleHTML

This is the function that turns out the SimpleHTML object

The first attribute is used as the element. The second and third attributes are used as contents or attributes of the new element depending on type. As SimpleXML is UTF8 only, non UTF8 characters will be removed or replaced as best as possible.

Parameters

string $element

Base node

mixed $a

Contents

mixed $b

Attributes

Returns

\SimpleHTML

Newly created node