Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

preg_replace /e will be deprecated in 5.5.0

  • Loading branch information...
commit 72a0a86ae02847bd76df250d1e75028550e4527b 1 parent 5730918
@tommyrot authored
Showing with 9 additions and 4 deletions.
  1. +8 −3 parser.php
  2. +1 −1  urltools.php
View
11 parser.php
@@ -260,7 +260,7 @@
* 2. Pass it on to rebuild_line() and replace the character with an empty string effectively making $line shorter.
* 3. Continue until $line is zero bytes in length.
*/
- $line = preg_replace('/^('.$this->hex_validutf8.'|.)/es', '$this->rebuild_line(\'$0\')', $line);
+ $line = preg_replace_callback('/^('.$this->hex_validutf8.'|.)/s', 'self::rebuild_line', $line);
}
/*
@@ -326,9 +326,14 @@
/**
* Build a new line consisting of valid UTF-8 from the characters passed along in $char.
*/
- final private function rebuild_line($char)
+ final private function rebuild_line($matches)
{
/**
+ * $char is passed along as the first element of the array $matches (see preg_replace_callback).
+ */
+ $char = $matches[0];
+
+ /**
* 1. Valid UTF-8 is passed along unmodified.
* 2. Single byte characters from the Latin-1 Supplement are converted to multibyte unicode.
* 3. Everything else is converted to the unicode questionmark sign (commonly used to depict unknown characters).
@@ -336,7 +341,7 @@
if (preg_match('/^'.$this->hex_validutf8.'$/', $char)) {
$this->newline .= $char;
} elseif (preg_match('/^'.$this->hex_latin1supplement.'$/', $char)) {
- $char = preg_replace('/^'.$this->hex_latin1supplement.'$/e', 'pack(\'C*\', (ord(\'$0\') >> 6) | 0xC0, (ord(\'$0\') & 0x3F) | 0x80)', $char);
+ $char = preg_replace_callback('/^'.$this->hex_latin1supplement.'$/', create_function('$matches', 'return pack(\'C*\', (ord($matches[0]) >> 6) | 0xC0, (ord($matches[0]) & 0x3F) | 0x80);'), $char);
$this->newline .= $char;
} else {
$this->newline .= "\xEF\xBF\xBD";
View
2  urltools.php
@@ -83,7 +83,7 @@ public function get_elements($url)
/**
* Convert scheme and authority to lower case.
*/
- $url = preg_replace('/^'.$this->scheme.'?'.$this->authority.'/ei', 'strtolower(\'$0\')', $url);
+ $url = preg_replace_callback('/^'.$this->scheme.'?'.$this->authority.'/i', create_function('$matches', 'return strtolower($matches[0]);'), $url);
/**
* Validate and further process the URL.
Please sign in to comment.
Something went wrong with that request. Please try again.