diff --git a/README.md b/README.md
index 305415e..78fe895 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,10 @@ To get started using pQuery do the following.
The following example parses an html string and does some manipulation on it.
```php
+
+// composer autoload
+require "vendor/autoload.php";
+
$html = '
Hello
Cruel
diff --git a/gan_tokenizer.php b/gan_tokenizer.php
index 1b6a98b..50dc0c5 100644
--- a/gan_tokenizer.php
+++ b/gan_tokenizer.php
@@ -57,6 +57,12 @@ class TokenizerBase {
* @access private
*/
var $doc = '';
+
+ /**
+ * The document as string in lowercase for faster search in next_pos()
+ * @var string
+ */
+ var $doc_lower = '';
/**
* The size of the document (length of string)
@@ -184,6 +190,7 @@ function __construct($doc = '', $pos = 0) {
*/
function setDoc($doc, $pos = 0) {
$this->doc = $doc;
+ $this->doc_lower = strtolower($doc);
$this->size = strlen($doc);
$this->setPos($pos);
}
@@ -489,7 +496,10 @@ function next_search($characters, $callback = true) {
*/
function next_pos($needle, $callback = true) {
$this->token_start = $this->pos;
- if (($this->pos < $this->size) && (($p = stripos($this->doc, $needle, $this->pos + 1)) !== false)) {
+
+ $needle_lower = strtolower($needle);
+
+ if (($this->pos < $this->size) && (($p = strpos($this->doc_lower, $needle_lower, $this->pos + 1)) !== false)) {
$len = $p - $this->pos - 1;
if ($len > 0) {
diff --git a/ganon.php b/ganon.php
index 1f80ebd..f4ce74b 100644
--- a/ganon.php
+++ b/ganon.php
@@ -30,14 +30,7 @@ function str_get_dom($str, $return_root = true) {
* @return Html5Parser|DomNode
*/
function file_get_dom($file, $return_root = true, $use_include_path = false, $context = null) {
- if (version_compare(PHP_VERSION, '5.0.0', '>='))
- $f = file_get_contents($file, $use_include_path, $context);
- else {
- if ($context !== null)
- trigger_error('Context parameter not supported in this PHP version');
- $f = file_get_contents($file, $use_include_path);
- }
-
+ $f = file_get_contents($file, $use_include_path, $context);
return (($f === false) ? false : str_get_dom($f, $return_root));
}
@@ -52,40 +45,6 @@ function dom_format(&$root, $options = array()) {
return $formatter->format($root);
}
-if (version_compare(PHP_VERSION, '5.0.0', '<')) {
- /**
- * PHP alternative to str_split, for backwards compatibility
- * @param string $string
- * @return string
- */
- function str_split($string) {
- $res = array();
- $size = strlen($string);
- for ($i = 0; $i < $size; $i++) {
- $res[] = $string[$i];
- }
-
- return $res;
- }
-}
-
-if (version_compare(PHP_VERSION, '5.2.0', '<')) {
- /**
- * PHP alternative to array_fill_keys, for backwards compatibility
- * @param array $keys
- * @param mixed $value
- * @return array
- */
- function array_fill_keys($keys, $value) {
- $res = array();
- foreach($keys as $k) {
- $res[$k] = $value;
- }
-
- return $res;
- }
-}
-
#!! <- Ignore when converting to single file
if (!defined('GANON_NO_INCLUDES')) {
define('GANON_NO_INCLUDES', true);
diff --git a/pQuery.php b/pQuery.php
index 7d451e8..0f28d00 100644
--- a/pQuery.php
+++ b/pQuery.php
@@ -48,12 +48,14 @@ public function append($content) {
}
public function attr($name, $value = null) {
- if (empty($this->nodes) && $value === null)
+ if (empty($this->nodes) && $value === null){
return '';
+ }
foreach ($this->nodes as $node) {
- if ($value === null)
+ if ($value === null){
return $node->attr($name);
+ }
$node->attr($name, $value);
}
return $this;
@@ -100,19 +102,22 @@ public function getIterator() {
public function hasClass($classname) {
foreach ($this->nodes as $node) {
- if ($node->hasClass($classname))
+ if ($node->hasClass($classname)){
return true;
+ }
}
return false;
}
public function html($value = null) {
- if (empty($this->nodes) && $value === null)
+ if (empty($this->nodes) && $value === null){
return '';
+ }
foreach ($this->nodes as $node) {
- if ($value === null)
+ if ($value === null){
return $node->html();
+ }
$node->html($value);
}
return $this;
@@ -173,12 +178,14 @@ public function prepend($content = null) {
}
public function prop($name, $value = null) {
- if (empty($this->nodes) && $value === null)
+ if (empty($this->nodes) && $value === null){
return '';
+ }
foreach ($this->nodes as $node) {
- if ($value === null)
+ if ($value === null){
return $node->prop($name);
+ }
$node->prop($name, $value);
}
return $this;
@@ -188,8 +195,9 @@ public function remove($selector = null) {
foreach ($this->nodes as $node) {
$node->remove($selector);
}
- if ($selector === null)
+ if ($selector === null){
$this->nodes = array();
+ }
return $this;
}
@@ -217,20 +225,23 @@ public function replaceWith($content) {
public function tagName($value = null) {
foreach ($this->nodes as $node) {
- if ($value === null)
+ if ($value === null){
return $node->tagName();
+ }
$node->tagName($value);
}
return $this;
}
public function text($value = null) {
- if (empty($this->nodes) && $value === null)
+ if (empty($this->nodes) && $value === null){
return '';
+ }
foreach ($this->nodes as $node) {
- if ($value === null)
+ if ($value === null){
return $node->text();
+ }
$node->text($value);
}
return $this;
@@ -252,12 +263,14 @@ public function unwrap() {
}
public function val($value = null) {
- if (empty($this->nodes) && $value === null)
+ if (empty($this->nodes) && $value === null){
return '';
+ }
foreach ($this->nodes as $node) {
- if ($value === null)
+ if ($value === null){
return $node->val();
+ }
$node->val($value);
}
return $this;