Edit File by line
/home/barbar84/public_h.../wp-inclu.../SimplePi...
File: IRI.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* SimplePie
[2] Fix | Delete
*
[3] Fix | Delete
* A PHP-Based RSS and Atom Feed Framework.
[4] Fix | Delete
* Takes the hard work out of managing a complete RSS/Atom solution.
[5] Fix | Delete
*
[6] Fix | Delete
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
[7] Fix | Delete
* All rights reserved.
[8] Fix | Delete
*
[9] Fix | Delete
* Redistribution and use in source and binary forms, with or without modification, are
[10] Fix | Delete
* permitted provided that the following conditions are met:
[11] Fix | Delete
*
[12] Fix | Delete
* * Redistributions of source code must retain the above copyright notice, this list of
[13] Fix | Delete
* conditions and the following disclaimer.
[14] Fix | Delete
*
[15] Fix | Delete
* * Redistributions in binary form must reproduce the above copyright notice, this list
[16] Fix | Delete
* of conditions and the following disclaimer in the documentation and/or other materials
[17] Fix | Delete
* provided with the distribution.
[18] Fix | Delete
*
[19] Fix | Delete
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
[20] Fix | Delete
* to endorse or promote products derived from this software without specific prior
[21] Fix | Delete
* written permission.
[22] Fix | Delete
*
[23] Fix | Delete
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
[24] Fix | Delete
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
[25] Fix | Delete
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
[26] Fix | Delete
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
[27] Fix | Delete
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
[28] Fix | Delete
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
[29] Fix | Delete
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
[30] Fix | Delete
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
[31] Fix | Delete
* POSSIBILITY OF SUCH DAMAGE.
[32] Fix | Delete
*
[33] Fix | Delete
* @package SimplePie
[34] Fix | Delete
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
[35] Fix | Delete
* @author Ryan Parman
[36] Fix | Delete
* @author Sam Sneddon
[37] Fix | Delete
* @author Ryan McCue
[38] Fix | Delete
* @link http://simplepie.org/ SimplePie
[39] Fix | Delete
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
[40] Fix | Delete
*/
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* IRI parser/serialiser/normaliser
[44] Fix | Delete
*
[45] Fix | Delete
* @package SimplePie
[46] Fix | Delete
* @subpackage HTTP
[47] Fix | Delete
* @author Sam Sneddon
[48] Fix | Delete
* @author Steve Minutillo
[49] Fix | Delete
* @author Ryan McCue
[50] Fix | Delete
* @copyright 2007-2012 Sam Sneddon, Steve Minutillo, Ryan McCue
[51] Fix | Delete
* @license http://www.opensource.org/licenses/bsd-license.php
[52] Fix | Delete
*/
[53] Fix | Delete
class SimplePie_IRI
[54] Fix | Delete
{
[55] Fix | Delete
/**
[56] Fix | Delete
* Scheme
[57] Fix | Delete
*
[58] Fix | Delete
* @var string
[59] Fix | Delete
*/
[60] Fix | Delete
protected $scheme = null;
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* User Information
[64] Fix | Delete
*
[65] Fix | Delete
* @var string
[66] Fix | Delete
*/
[67] Fix | Delete
protected $iuserinfo = null;
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* ihost
[71] Fix | Delete
*
[72] Fix | Delete
* @var string
[73] Fix | Delete
*/
[74] Fix | Delete
protected $ihost = null;
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Port
[78] Fix | Delete
*
[79] Fix | Delete
* @var string
[80] Fix | Delete
*/
[81] Fix | Delete
protected $port = null;
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* ipath
[85] Fix | Delete
*
[86] Fix | Delete
* @var string
[87] Fix | Delete
*/
[88] Fix | Delete
protected $ipath = '';
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* iquery
[92] Fix | Delete
*
[93] Fix | Delete
* @var string
[94] Fix | Delete
*/
[95] Fix | Delete
protected $iquery = null;
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* ifragment
[99] Fix | Delete
*
[100] Fix | Delete
* @var string
[101] Fix | Delete
*/
[102] Fix | Delete
protected $ifragment = null;
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* Normalization database
[106] Fix | Delete
*
[107] Fix | Delete
* Each key is the scheme, each value is an array with each key as the IRI
[108] Fix | Delete
* part and value as the default value for that part.
[109] Fix | Delete
*/
[110] Fix | Delete
protected $normalization = array(
[111] Fix | Delete
'acap' => array(
[112] Fix | Delete
'port' => 674
[113] Fix | Delete
),
[114] Fix | Delete
'dict' => array(
[115] Fix | Delete
'port' => 2628
[116] Fix | Delete
),
[117] Fix | Delete
'file' => array(
[118] Fix | Delete
'ihost' => 'localhost'
[119] Fix | Delete
),
[120] Fix | Delete
'http' => array(
[121] Fix | Delete
'port' => 80,
[122] Fix | Delete
'ipath' => '/'
[123] Fix | Delete
),
[124] Fix | Delete
'https' => array(
[125] Fix | Delete
'port' => 443,
[126] Fix | Delete
'ipath' => '/'
[127] Fix | Delete
),
[128] Fix | Delete
);
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* Return the entire IRI when you try and read the object as a string
[132] Fix | Delete
*
[133] Fix | Delete
* @return string
[134] Fix | Delete
*/
[135] Fix | Delete
public function __toString()
[136] Fix | Delete
{
[137] Fix | Delete
return $this->get_iri();
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* Overload __set() to provide access via properties
[142] Fix | Delete
*
[143] Fix | Delete
* @param string $name Property name
[144] Fix | Delete
* @param mixed $value Property value
[145] Fix | Delete
*/
[146] Fix | Delete
public function __set($name, $value)
[147] Fix | Delete
{
[148] Fix | Delete
if (method_exists($this, 'set_' . $name))
[149] Fix | Delete
{
[150] Fix | Delete
call_user_func(array($this, 'set_' . $name), $value);
[151] Fix | Delete
}
[152] Fix | Delete
elseif (
[153] Fix | Delete
$name === 'iauthority'
[154] Fix | Delete
|| $name === 'iuserinfo'
[155] Fix | Delete
|| $name === 'ihost'
[156] Fix | Delete
|| $name === 'ipath'
[157] Fix | Delete
|| $name === 'iquery'
[158] Fix | Delete
|| $name === 'ifragment'
[159] Fix | Delete
)
[160] Fix | Delete
{
[161] Fix | Delete
call_user_func(array($this, 'set_' . substr($name, 1)), $value);
[162] Fix | Delete
}
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* Overload __get() to provide access via properties
[167] Fix | Delete
*
[168] Fix | Delete
* @param string $name Property name
[169] Fix | Delete
* @return mixed
[170] Fix | Delete
*/
[171] Fix | Delete
public function __get($name)
[172] Fix | Delete
{
[173] Fix | Delete
// isset() returns false for null, we don't want to do that
[174] Fix | Delete
// Also why we use array_key_exists below instead of isset()
[175] Fix | Delete
$props = get_object_vars($this);
[176] Fix | Delete
[177] Fix | Delete
if (
[178] Fix | Delete
$name === 'iri' ||
[179] Fix | Delete
$name === 'uri' ||
[180] Fix | Delete
$name === 'iauthority' ||
[181] Fix | Delete
$name === 'authority'
[182] Fix | Delete
)
[183] Fix | Delete
{
[184] Fix | Delete
$return = $this->{"get_$name"}();
[185] Fix | Delete
}
[186] Fix | Delete
elseif (array_key_exists($name, $props))
[187] Fix | Delete
{
[188] Fix | Delete
$return = $this->$name;
[189] Fix | Delete
}
[190] Fix | Delete
// host -> ihost
[191] Fix | Delete
elseif (($prop = 'i' . $name) && array_key_exists($prop, $props))
[192] Fix | Delete
{
[193] Fix | Delete
$name = $prop;
[194] Fix | Delete
$return = $this->$prop;
[195] Fix | Delete
}
[196] Fix | Delete
// ischeme -> scheme
[197] Fix | Delete
elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props))
[198] Fix | Delete
{
[199] Fix | Delete
$name = $prop;
[200] Fix | Delete
$return = $this->$prop;
[201] Fix | Delete
}
[202] Fix | Delete
else
[203] Fix | Delete
{
[204] Fix | Delete
trigger_error('Undefined property: ' . get_class($this) . '::' . $name, E_USER_NOTICE);
[205] Fix | Delete
$return = null;
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
if ($return === null && isset($this->normalization[$this->scheme][$name]))
[209] Fix | Delete
{
[210] Fix | Delete
return $this->normalization[$this->scheme][$name];
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
return $return;
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
/**
[217] Fix | Delete
* Overload __isset() to provide access via properties
[218] Fix | Delete
*
[219] Fix | Delete
* @param string $name Property name
[220] Fix | Delete
* @return bool
[221] Fix | Delete
*/
[222] Fix | Delete
public function __isset($name)
[223] Fix | Delete
{
[224] Fix | Delete
return method_exists($this, 'get_' . $name) || isset($this->$name);
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
/**
[228] Fix | Delete
* Overload __unset() to provide access via properties
[229] Fix | Delete
*
[230] Fix | Delete
* @param string $name Property name
[231] Fix | Delete
*/
[232] Fix | Delete
public function __unset($name)
[233] Fix | Delete
{
[234] Fix | Delete
if (method_exists($this, 'set_' . $name))
[235] Fix | Delete
{
[236] Fix | Delete
call_user_func(array($this, 'set_' . $name), '');
[237] Fix | Delete
}
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
/**
[241] Fix | Delete
* Create a new IRI object, from a specified string
[242] Fix | Delete
*
[243] Fix | Delete
* @param string $iri
[244] Fix | Delete
*/
[245] Fix | Delete
public function __construct($iri = null)
[246] Fix | Delete
{
[247] Fix | Delete
$this->set_iri($iri);
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
/**
[251] Fix | Delete
* Clean up
[252] Fix | Delete
*/
[253] Fix | Delete
public function __destruct() {
[254] Fix | Delete
$this->set_iri(null, true);
[255] Fix | Delete
$this->set_path(null, true);
[256] Fix | Delete
$this->set_authority(null, true);
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
/**
[260] Fix | Delete
* Create a new IRI object by resolving a relative IRI
[261] Fix | Delete
*
[262] Fix | Delete
* Returns false if $base is not absolute, otherwise an IRI.
[263] Fix | Delete
*
[264] Fix | Delete
* @param IRI|string $base (Absolute) Base IRI
[265] Fix | Delete
* @param IRI|string $relative Relative IRI
[266] Fix | Delete
* @return IRI|false
[267] Fix | Delete
*/
[268] Fix | Delete
public static function absolutize($base, $relative)
[269] Fix | Delete
{
[270] Fix | Delete
if (!($relative instanceof SimplePie_IRI))
[271] Fix | Delete
{
[272] Fix | Delete
$relative = new SimplePie_IRI($relative);
[273] Fix | Delete
}
[274] Fix | Delete
if (!$relative->is_valid())
[275] Fix | Delete
{
[276] Fix | Delete
return false;
[277] Fix | Delete
}
[278] Fix | Delete
elseif ($relative->scheme !== null)
[279] Fix | Delete
{
[280] Fix | Delete
return clone $relative;
[281] Fix | Delete
}
[282] Fix | Delete
else
[283] Fix | Delete
{
[284] Fix | Delete
if (!($base instanceof SimplePie_IRI))
[285] Fix | Delete
{
[286] Fix | Delete
$base = new SimplePie_IRI($base);
[287] Fix | Delete
}
[288] Fix | Delete
if ($base->scheme !== null && $base->is_valid())
[289] Fix | Delete
{
[290] Fix | Delete
if ($relative->get_iri() !== '')
[291] Fix | Delete
{
[292] Fix | Delete
if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null)
[293] Fix | Delete
{
[294] Fix | Delete
$target = clone $relative;
[295] Fix | Delete
$target->scheme = $base->scheme;
[296] Fix | Delete
}
[297] Fix | Delete
else
[298] Fix | Delete
{
[299] Fix | Delete
$target = new SimplePie_IRI;
[300] Fix | Delete
$target->scheme = $base->scheme;
[301] Fix | Delete
$target->iuserinfo = $base->iuserinfo;
[302] Fix | Delete
$target->ihost = $base->ihost;
[303] Fix | Delete
$target->port = $base->port;
[304] Fix | Delete
if ($relative->ipath !== '')
[305] Fix | Delete
{
[306] Fix | Delete
if ($relative->ipath[0] === '/')
[307] Fix | Delete
{
[308] Fix | Delete
$target->ipath = $relative->ipath;
[309] Fix | Delete
}
[310] Fix | Delete
elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '')
[311] Fix | Delete
{
[312] Fix | Delete
$target->ipath = '/' . $relative->ipath;
[313] Fix | Delete
}
[314] Fix | Delete
elseif (($last_segment = strrpos($base->ipath, '/')) !== false)
[315] Fix | Delete
{
[316] Fix | Delete
$target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
[317] Fix | Delete
}
[318] Fix | Delete
else
[319] Fix | Delete
{
[320] Fix | Delete
$target->ipath = $relative->ipath;
[321] Fix | Delete
}
[322] Fix | Delete
$target->ipath = $target->remove_dot_segments($target->ipath);
[323] Fix | Delete
$target->iquery = $relative->iquery;
[324] Fix | Delete
}
[325] Fix | Delete
else
[326] Fix | Delete
{
[327] Fix | Delete
$target->ipath = $base->ipath;
[328] Fix | Delete
if ($relative->iquery !== null)
[329] Fix | Delete
{
[330] Fix | Delete
$target->iquery = $relative->iquery;
[331] Fix | Delete
}
[332] Fix | Delete
elseif ($base->iquery !== null)
[333] Fix | Delete
{
[334] Fix | Delete
$target->iquery = $base->iquery;
[335] Fix | Delete
}
[336] Fix | Delete
}
[337] Fix | Delete
$target->ifragment = $relative->ifragment;
[338] Fix | Delete
}
[339] Fix | Delete
}
[340] Fix | Delete
else
[341] Fix | Delete
{
[342] Fix | Delete
$target = clone $base;
[343] Fix | Delete
$target->ifragment = null;
[344] Fix | Delete
}
[345] Fix | Delete
$target->scheme_normalization();
[346] Fix | Delete
return $target;
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
return false;
[350] Fix | Delete
}
[351] Fix | Delete
}
[352] Fix | Delete
[353] Fix | Delete
/**
[354] Fix | Delete
* Parse an IRI into scheme/authority/path/query/fragment segments
[355] Fix | Delete
*
[356] Fix | Delete
* @param string $iri
[357] Fix | Delete
* @return array
[358] Fix | Delete
*/
[359] Fix | Delete
protected function parse_iri($iri)
[360] Fix | Delete
{
[361] Fix | Delete
$iri = trim($iri, "\x20\x09\x0A\x0C\x0D");
[362] Fix | Delete
if (preg_match('/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/', $iri, $match))
[363] Fix | Delete
{
[364] Fix | Delete
if ($match[1] === '')
[365] Fix | Delete
{
[366] Fix | Delete
$match['scheme'] = null;
[367] Fix | Delete
}
[368] Fix | Delete
if (!isset($match[3]) || $match[3] === '')
[369] Fix | Delete
{
[370] Fix | Delete
$match['authority'] = null;
[371] Fix | Delete
}
[372] Fix | Delete
if (!isset($match[5]))
[373] Fix | Delete
{
[374] Fix | Delete
$match['path'] = '';
[375] Fix | Delete
}
[376] Fix | Delete
if (!isset($match[6]) || $match[6] === '')
[377] Fix | Delete
{
[378] Fix | Delete
$match['query'] = null;
[379] Fix | Delete
}
[380] Fix | Delete
if (!isset($match[8]) || $match[8] === '')
[381] Fix | Delete
{
[382] Fix | Delete
$match['fragment'] = null;
[383] Fix | Delete
}
[384] Fix | Delete
return $match;
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
// This can occur when a paragraph is accidentally parsed as a URI
[388] Fix | Delete
return false;
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
/**
[392] Fix | Delete
* Remove dot segments from a path
[393] Fix | Delete
*
[394] Fix | Delete
* @param string $input
[395] Fix | Delete
* @return string
[396] Fix | Delete
*/
[397] Fix | Delete
protected function remove_dot_segments($input)
[398] Fix | Delete
{
[399] Fix | Delete
$output = '';
[400] Fix | Delete
while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..')
[401] Fix | Delete
{
[402] Fix | Delete
// A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
[403] Fix | Delete
if (strpos($input, '../') === 0)
[404] Fix | Delete
{
[405] Fix | Delete
$input = substr($input, 3);
[406] Fix | Delete
}
[407] Fix | Delete
elseif (strpos($input, './') === 0)
[408] Fix | Delete
{
[409] Fix | Delete
$input = substr($input, 2);
[410] Fix | Delete
}
[411] Fix | Delete
// B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise,
[412] Fix | Delete
elseif (strpos($input, '/./') === 0)
[413] Fix | Delete
{
[414] Fix | Delete
$input = substr($input, 2);
[415] Fix | Delete
}
[416] Fix | Delete
elseif ($input === '/.')
[417] Fix | Delete
{
[418] Fix | Delete
$input = '/';
[419] Fix | Delete
}
[420] Fix | Delete
// C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise,
[421] Fix | Delete
elseif (strpos($input, '/../') === 0)
[422] Fix | Delete
{
[423] Fix | Delete
$input = substr($input, 3);
[424] Fix | Delete
$output = substr_replace($output, '', strrpos($output, '/'));
[425] Fix | Delete
}
[426] Fix | Delete
elseif ($input === '/..')
[427] Fix | Delete
{
[428] Fix | Delete
$input = '/';
[429] Fix | Delete
$output = substr_replace($output, '', strrpos($output, '/'));
[430] Fix | Delete
}
[431] Fix | Delete
// D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
[432] Fix | Delete
elseif ($input === '.' || $input === '..')
[433] Fix | Delete
{
[434] Fix | Delete
$input = '';
[435] Fix | Delete
}
[436] Fix | Delete
// E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer
[437] Fix | Delete
elseif (($pos = strpos($input, '/', 1)) !== false)
[438] Fix | Delete
{
[439] Fix | Delete
$output .= substr($input, 0, $pos);
[440] Fix | Delete
$input = substr_replace($input, '', 0, $pos);
[441] Fix | Delete
}
[442] Fix | Delete
else
[443] Fix | Delete
{
[444] Fix | Delete
$output .= $input;
[445] Fix | Delete
$input = '';
[446] Fix | Delete
}
[447] Fix | Delete
}
[448] Fix | Delete
return $output . $input;
[449] Fix | Delete
}
[450] Fix | Delete
[451] Fix | Delete
/**
[452] Fix | Delete
* Replace invalid character with percent encoding
[453] Fix | Delete
*
[454] Fix | Delete
* @param string $string Input string
[455] Fix | Delete
* @param string $extra_chars Valid characters not in iunreserved or
[456] Fix | Delete
* iprivate (this is ASCII-only)
[457] Fix | Delete
* @param bool $iprivate Allow iprivate
[458] Fix | Delete
* @return string
[459] Fix | Delete
*/
[460] Fix | Delete
protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false)
[461] Fix | Delete
{
[462] Fix | Delete
// Normalize as many pct-encoded sections as possible
[463] Fix | Delete
$string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array($this, 'remove_iunreserved_percent_encoded'), $string);
[464] Fix | Delete
[465] Fix | Delete
// Replace invalid percent characters
[466] Fix | Delete
$string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string);
[467] Fix | Delete
[468] Fix | Delete
// Add unreserved and % to $extra_chars (the latter is safe because all
[469] Fix | Delete
// pct-encoded sections are now valid).
[470] Fix | Delete
$extra_chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%';
[471] Fix | Delete
[472] Fix | Delete
// Now replace any bytes that aren't allowed with their pct-encoded versions
[473] Fix | Delete
$position = 0;
[474] Fix | Delete
$strlen = strlen($string);
[475] Fix | Delete
while (($position += strspn($string, $extra_chars, $position)) < $strlen)
[476] Fix | Delete
{
[477] Fix | Delete
$value = ord($string[$position]);
[478] Fix | Delete
[479] Fix | Delete
// Start position
[480] Fix | Delete
$start = $position;
[481] Fix | Delete
[482] Fix | Delete
// By default we are valid
[483] Fix | Delete
$valid = true;
[484] Fix | Delete
[485] Fix | Delete
// No one byte sequences are valid due to the while.
[486] Fix | Delete
// Two byte sequence:
[487] Fix | Delete
if (($value & 0xE0) === 0xC0)
[488] Fix | Delete
{
[489] Fix | Delete
$character = ($value & 0x1F) << 6;
[490] Fix | Delete
$length = 2;
[491] Fix | Delete
$remaining = 1;
[492] Fix | Delete
}
[493] Fix | Delete
// Three byte sequence:
[494] Fix | Delete
elseif (($value & 0xF0) === 0xE0)
[495] Fix | Delete
{
[496] Fix | Delete
$character = ($value & 0x0F) << 12;
[497] Fix | Delete
$length = 3;
[498] Fix | Delete
$remaining = 2;
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function