Use str_starts_with and str_ends_with instead

This commit is contained in:
Robin van der Vliet
2025-11-10 19:27:37 +01:00
parent fc48bce36d
commit c48c10728d
6 changed files with 8 additions and 8 deletions
@@ -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;
}
+1 -1
View File
@@ -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);
+3 -3
View File
@@ -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);
@@ -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);
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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));
}