diff --git a/composer.json b/composer.json index d48b460..46d6986 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,16 @@ ], "require": { "php": ">=5.3", - "ext-curl": "*", - "ext-mbstring": "*" + "ext-curl": "*" }, "require-dev": { "ext-gd": "*", "phpunit/phpunit": "*", "squizlabs/php_codesniffer": "*" }, + "suggest": { + "ext-mbstring": "*" + }, "autoload": { "psr-4": { "Curl\\": "src/Curl/" diff --git a/src/Curl/StringUtil.php b/src/Curl/StringUtil.php index 39bf48c..a8565eb 100644 --- a/src/Curl/StringUtil.php +++ b/src/Curl/StringUtil.php @@ -15,6 +15,6 @@ class StringUtil */ public static function startsWith($haystack, $needle) { - return \mb_substr($haystack, 0, \mb_strlen($needle)) === $needle; + return (function_exists("\mb_substr") ? (\mb_substr($haystack, 0, \mb_strlen($needle)) === $needle) : (\substr($haystack, 0, \strlen($needle)) === $needle)); } } diff --git a/src/Curl/Url.php b/src/Curl/Url.php index e31715e..7ae6fff 100644 --- a/src/Curl/Url.php +++ b/src/Curl/Url.php @@ -56,10 +56,10 @@ class Url // buffer; otherwise, } elseif (StringUtil::startsWith($input, '/../')) { $input = substr($input, 3); - $output = substr_replace($output, '', \mb_strrpos($output, '/')); + $output = substr_replace($output, '', (function_exists('\mb_strrpos') ? \mb_strrpos($output, '/') : \strrpos($output, '/'))); } elseif ($input === '/..') { $input = '/'; - $output = substr_replace($output, '', \mb_strrpos($output, '/')); + $output = substr_replace($output, '', (function_exists('\mb_strrpos') ? \mb_strrpos($output, '/') : \strrpos($output, '/') )); // D. if the input buffer consists only of "." or "..", then remove // that from the input buffer; otherwise, @@ -70,7 +70,7 @@ class Url // 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. - } elseif (!(($pos = \mb_strpos($input, '/', 1)) === false)) { + } elseif (!(($pos = (function_exists('\mb_strpos') ? \mb_strpos($input, '/', 1) : \strpos($input, '/', 1) )) === false)) { $output .= substr($input, 0, $pos); $input = substr_replace($input, '', 0, $pos); } else { @@ -131,7 +131,7 @@ class Url if (StringUtil::startsWith($r['path'], '/')) { $target['path'] = self::removeDotSegments($r['path']); } else { - $base = \mb_strrchr($b['path'], '/', true); + $base = (function_exists('\mb_strrchr') ? \mb_strrchr($b['path'], '/', true) : \strrchr($b['path'], '/')); if ($base === false) { $base = ''; }