All Projects → amal → CDom

amal / CDom

Licence: other
Simple HTML/XML/BBCode DOM component for PHP.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to CDom

Css Select
a CSS selector compiler & engine
Stars: ✭ 279 (+973.08%)
Mutual labels:  dom, css-selector
ElementFinder
Fetch data from HTML and XML via xpath/css and prepare it with regexp
Stars: ✭ 29 (+11.54%)
Mutual labels:  dom, css-selector
Dom
Modern DOM API.
Stars: ✭ 88 (+238.46%)
Mutual labels:  dom, css-selector
Browser Monkey
Reliable DOM testing
Stars: ✭ 53 (+103.85%)
Mutual labels:  dom, css-selector
zig-wasm-dom
Zig + WebAssembly + JS + DOM
Stars: ✭ 81 (+211.54%)
Mutual labels:  dom
CustomWebCheckbox
An example of a make checkbox design on the web.
Stars: ✭ 12 (-53.85%)
Mutual labels:  css-selector
modulor-html
Missing template engine for Web Components
Stars: ✭ 36 (+38.46%)
Mutual labels:  dom
emerj
Emerj is a tiny JavaScript library to render live HTML/DOM updates efficiently and non-destructively, by merging an updated DOM with the live DOM, and only changing those elements that differ.
Stars: ✭ 56 (+115.38%)
Mutual labels:  dom
object-dom
HTML Object Declarative Dom
Stars: ✭ 20 (-23.08%)
Mutual labels:  dom
anim8js
The ultimate animation library for javascript - animate everything!
Stars: ✭ 33 (+26.92%)
Mutual labels:  dom
attoparser
A tiny but fast java event-style markup parser.
Stars: ✭ 46 (+76.92%)
Mutual labels:  dom
s2
A function for reactive web UI.
Stars: ✭ 43 (+65.38%)
Mutual labels:  dom
recks
🐶 React-like RxJS-based framework
Stars: ✭ 133 (+411.54%)
Mutual labels:  dom
bbcode
A BBCode parser and converter written in PHP.
Stars: ✭ 32 (+23.08%)
Mutual labels:  bbcode
GQ
CSS Selector Engine for Gumbo Parser
Stars: ✭ 25 (-3.85%)
Mutual labels:  css-selector
bassdrum
reactive, type safe components with preact and rxjs.
Stars: ✭ 44 (+69.23%)
Mutual labels:  dom
parsed-html-rewriter
A DOM-based implementation of Cloudflare Worker's HTMLRewriter.
Stars: ✭ 34 (+30.77%)
Mutual labels:  dom
lego
🚀 Web-components made lightweight & Future-Proof.
Stars: ✭ 69 (+165.38%)
Mutual labels:  dom
dom-inspector
Dom inspect like chrome dev tools.
Stars: ✭ 124 (+376.92%)
Mutual labels:  dom
AdvancedHTMLParser
Fast Indexed python HTML parser which builds a DOM node tree, providing common getElementsBy* functions for scraping, testing, modification, and formatting. Also XPath.
Stars: ✭ 90 (+246.15%)
Mutual labels:  dom

CDom

https://github.com/amal/CDom

CDom is a simple HTML/XML/BBCode DOM component. It provides a parser for HTML-like markup language in the DOM-like structure and support searching through the DOM with full strength of CSS3 selectors and any manipulations. CDom is based on PHP Simple HTML DOM Parser and licensed under the MIT License.

Main features and possibilites:

  • Traversing and manipulations in jQuery-like manner for PHP.
  • Automatic detection of encoding.
  • Supports damaged and malformed html.
  • Full support of CSS3 selectors.
  • Support of jQuery selector extensions.
  • Extract contents from DOM as text or html in a single line.
  • Full code coverage.
  • Can work with simple BBCode or other HTML-like markup languages.

CDom is written for Anizoptera CMF by Amal Samally (amal.samally at gmail.com)

Documentation

CDom use is very simple. Most of the methods match the jQuery's ones. All methods are detail commented. Your IDE can easy show autocompletion, if support PHPDoc. And you can see examples of using below. Full documentation will be soon.

Requirements

  • CDom requires PHP 5.3.0 (or later).

Examples

How to get HTML elements?

// Create DOM from string
$html = file_get_contents('http://www.google.com/');
$dom  = CDom::fromString($html);

// Find all images
foreach($dom->find('img') as $element) {
	echo $element->src . "\n";
}

// Find all links
foreach($dom->find('a') as $element) {
	echo $element->href . "\n";
}

How to modify HTML elements?

// Create DOM from string
$dom = CDom::fromString('<div id="hello">Hello</div><div id="world">World</div>');

// Add class to the second div (first last child)
$dom->find('div:nth-last-child(1)')->class = 'bar';

// Change text of first div
$dom->find('div[id=hello]')->text('foo');

echo $dom . "\n"; // Output: <div id="hello">foo</div><div id="world" class="bar">World</div>

Extract contents from HTML

$html = file_get_contents('http://www.google.com/');
// Dump correctly formatted contents without tags from HTML
echo CDom::fromString($html)->text() . "\n";

Use CDom to work with simple BBCode

$bbMarkup = <<<'TXT'
[quote]
	[b]Bold [u]Underline[/u][/b]
	[i]Italic
[/quote]
[img width=12 height=16]url[/img]
TXT;
CDom::$bracketOpen  = '[';
CDom::$bracketClose = ']';

CDom::$blockTags  = array('quote' => true);
CDom::$inlineTags = array('b' => true, 'i' => true, 'u' => true);
CDom::$selfClosingTags = array();

// Create DOM from string
$dom = CDom::fromString($bbMarkup);

// Find [b]
$b = $dom->find('b');
$expected = '[b]Bold [u]Underline[/u][/b]';
echo $b->outerHtml() . "\n"; // Output: [b]Bold [u]Underline[/u][/b]

// Change [img] width
$img = $dom->lastChild;
$img->width = 450;
echo $img->outerHtml() . "\n"; // Output: [img width="450" height="16"]url[/img]

// Convert [b] to html
CDom::$bracketOpen  = '<';
CDom::$bracketClose = '>';
echo $b->outerHtml() . "\n"; // Output: <b>Bold <u>Underline</u></b>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].