diff --git a/src/PhpSpreadsheet/Calculation/Information/Value.php b/src/PhpSpreadsheet/Calculation/Information/Value.php index 57a6704df..2f949cd05 100644 --- a/src/PhpSpreadsheet/Calculation/Information/Value.php +++ b/src/PhpSpreadsheet/Calculation/Information/Value.php @@ -265,7 +265,7 @@ class Value if (is_bool($value)) { return (int) $value; } - if (is_string($value) && substr($value, 0, 1) === '#') { + if (is_string($value) && str_starts_with($value, '#')) { return $value; } diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index 2a84c0deb..5aa96f44b 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -316,7 +316,7 @@ abstract class Coordinate $worksheet = $matches['worksheet']; if ($worksheet !== '') { - if (substr($worksheet, 0, 1) === "'" && substr($worksheet, -1, 1) === "'") { + if (str_starts_with($worksheet, "'") && str_ends_with($worksheet, "'")) { $worksheet = substr($worksheet, 1, -1); } $data['worksheet'] = strtolower($worksheet); diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 0723914b6..b6091ae29 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -1129,7 +1129,7 @@ class Html extends BaseReader $styleArray = self::getStyleArray($attributes); $src = $attributes['src']; - if (substr($src, 0, 5) !== 'data:') { + if (!str_starts_with($src, 'data:')) { $src = urldecode($src); } $width = isset($attributes['width']) ? (float) $attributes['width'] : ($styleArray['width'] ?? null); @@ -1195,13 +1195,13 @@ class Html extends BaseReader $arrayKey = trim($value[0]); $arrayValue = trim($value[1]); if ($arrayKey === 'width') { - if (substr($arrayValue, -2) === 'px') { + if (str_ends_with($arrayValue, 'px')) { $arrayValue = (string) (((float) substr($arrayValue, 0, -2))); } else { $arrayValue = (new CssDimension($arrayValue))->toUnit(CssDimension::UOM_PIXELS); } } elseif ($arrayKey === 'height') { - if (substr($arrayValue, -2) === 'px') { + if (str_ends_with($arrayValue, 'px')) { $arrayValue = substr($arrayValue, 0, -2); } else { $arrayValue = (new CssDimension($arrayValue))->toUnit(CssDimension::UOM_PIXELS); diff --git a/src/PhpSpreadsheet/Reader/Security/XmlScanner.php b/src/PhpSpreadsheet/Reader/Security/XmlScanner.php index e4da44f31..7b4e10431 100644 --- a/src/PhpSpreadsheet/Reader/Security/XmlScanner.php +++ b/src/PhpSpreadsheet/Reader/Security/XmlScanner.php @@ -64,7 +64,7 @@ class XmlScanner private function findCharSet(string $xml): string { - if (substr($xml, 0, 4) === "\x4c\x6f\xa7\x94") { + if (str_starts_with($xml, "\x4c\x6f\xa7\x94")) { throw new Reader\Exception('EBCDIC encoding not permitted'); } $encoding = Reader\Csv::guessEncodingBom('', $xml); diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 829f81fe3..2ae91dd6d 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -2430,7 +2430,7 @@ class Xlsx extends BaseReader $attrs = $rel->attributes() ?? []; $rid = (string) ($attrs['Id'] ?? ''); $target = (string) ($attrs['Target'] ?? ''); - if ($rid === $id && substr($target, 0, 2) === '..') { + if ($rid === $id && str_starts_with($target, '..')) { $target = 'xl' . substr($target, 2); $content = $this->getFromZipArchive($this->zip, $target); $docSheet->setBackgroundImage($content); diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php index 64c4ec23a..3defaea16 100644 --- a/src/PhpSpreadsheet/Worksheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -3411,7 +3411,7 @@ class Worksheet public static function unApostrophizeTitle(?string $title): string { $title ??= ''; - if ($title[0] === "'" && substr($title, -1) === "'") { + if (str_starts_with($title, "'") && str_ends_with($title, "'")) { $title = str_replace("''", "'", substr($title, 1, -1)); }