PHP 8 Solutions by David Powers

PHP 8 Solutions by David Powers

Author:David Powers
Language: eng
Format: epub
ISBN: 9781484271414
Publisher: Apress


JPEG, PNG, and GIF are universally supported by browsers; I have also included WebP because support is now widespread. All image MIME types begin with image/. To make the value easier to use later, the substr() function extracts the characters after the slash and stores them in the $imageType property. When used with two arguments, substr() starts at the position (counting from 0) specified in the second argument and returns the rest of the string. Rather than use a fixed number as the second argument, I have used the strpos() function to find the position of the slash and added 1. This makes the code more generic because some proprietary image formats begin with application/ rather than image/. The first argument to strpos() is the entire string you’re searching in, and the second is the string you’re searching for.6.

The setSuffix() method needs to make sure the value doesn’t contain any special characters. The code looks like this:protected function setSuffix($suffix) {

if (preg_match('/^\w+$/', $suffix)) {

if (!str_starts_with($suffix, '_')) {

return '_' . $suffix;

} else {

return $suffix;

}

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.