- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1046 Articles for PHP
2K+ Views
In PHP, imagecreatefrompng() is an inbuilt function that is used to create a new image from a PNG file or URL. imagecreatefrompng() returns an image identifier representing the image obtained from the given filename.Syntaxresource imagecreatefrompng(string $filename)Parametersimagecreatefrompng() takes only one parameter, $filename. This parameter holds the name of the image or path to the PNG image.Return Valuesimagecreatefrompng() returns an image resource identifier on success, and it gives an error on false.Example 1 − Showing the loaded PNG image in the browserOutputExample 2 − Loaded and saving PNG image in the local drive pathOutputExplanation − In Example 2, a png image is ... Read More
2K+ Views
imagecreatefromjpeg() is an inbuilt function in PHP that is used to create a new image from a JPEG file. It returns an image identifier representing the image obtained from the given filename.Syntaxresource imagecreatefromjpeg(string $filename)Parametersimagecreatefromjpeg() uses only one parameter, $filename, that holds the name of the image or path to the JPEG image.Return Valuesimagecreatefromjpeg() returns an image resource identifier on success, and it gives an error on false.Example 1OutputExample 2Input ImageOutput ImageExplanation − In Example 2, we loaded the jpeg image from the local path using the imagecreatefromjpeg() function. Thereafter, we used the imageflip() function to flip the image.Example 3 − ... Read More
381 Views
PHP 8 uses a new built-in exception ValueError. PHP throws this exception when we pass a value to a function, which has a valid type but cannot be used for operation. In the earlier versions of PHP, we used to get a Warning error in such cases, but PHP 8 will show a ValueError.Example: ValueError in PHP 8OutputFatal error: Uncaught ValueError: array_rand(): Argument #1 ($array) cannot be emptyExample Live DemoOutputbool(false)Example: ValueError in PHP 8OutputFatal error: Uncaught ValueError: array_rand(): Argument #1 ($array) cannot be empty
232 Views
The resource is a type of variable that holds a reference to an external resource. The resource can be a filehandle, a database connection, or a URL handle. Every resource is identified by a unique id. In the previous versions of PHP, we needed to cast a resource to int to get the resource id.Example: get_recource_id using int.Output1In PHP 8, the get_resource_id() function always returns an int. It is used to get the ID for a given resource. This function always guarantees type safety.Example: Using get_recource_id in PHP 8.Output1
243 Views
In the previous versions of PHP, if we wanted to catch an exception, then we needed it to store in a variable to check whether that variable is used or not.Before PHP 8, to handle the exception catch block, we needed to catch the exception (thrown by the try block) to a variable.Example: Capturing Exception Catches in PHPExplanation − In the above program, the exception is being caught by the catch block to a variable $e. Now the $e variable can hold any information about the exception as code, message, etc.PHP 8 introduced non-capturing catches. Now, it is possible to ... Read More
276 Views
In PHP 8, fdiv() function is used to perform floating-point division on IEEE 754 standard. fdiv() is a mathematical operation that divides two numbers and returns a floating-point number.The fdiv() function works similar to the intdiv() and fmod() function, which allows division by zero. Instead of showing an error, the fdiv() function returns INF, -INF or NAN, when a number is divided by zero.INF (Infinity or real number) – It is the result of a numerical calculation that is mathematically infinite.-INF (Negative Infinite) – it is a negative infinite number or a number below -1.796E308.NAN (Not a Number) – it ... Read More
275 Views
In the earlier versions of PHP, if we wanted to get the type of a variable, we used to employ the gettype() function. This function returns the type of a variable in the custom of a string. It returns all possible values like integer, string, array, boolean, double, resource, NULL, unknown type, etc.However, there were issues in the gettype function. It does not return native and familiar type names. It returns double instead of float and integer instead of int, and so on.To overcome this problem, PHP 8 uses the get_debug_type function.get_debug_type() functionIn PHP 8, the get_debug_type function returns the ... Read More
184 Views
str_starts_with and str_ends_with function are added in PHP 8 to check if a given string starts or ends with another string or not. If it starts and ends with another string, it returns true, otherwise false.Examplestr_starts_with('hello haystack', 'hello'); //starts string found 'True' str_starts_with('hello haystack', 'stack'); //ends string found 'True'str_starts_with('hello haystack', 'hay'); //starts string found 'False' str_starts_with('hello haystack', 'hay'); //ends string found 'False'str_starts_with() function in PHP 8This function checks if a given string starts with the string needle. It returns true if the first string is found, otherwise false.str_starts_with(string $haystack, string $needle): boolExample : using str_starts_with() function.OutputString starts with 'hello'Note: If ... Read More
2K+ Views
In PHP 8, str_contains function determines if a string contains a given substring anywhere. The str_contains function checks if a first-string is contained in the second string and it returns a true /false Boolean value based on whether the string is found or not. it is a self-explanatory function.str_contains(string $haystack, string $needle): boolExample1 : PHP 8 str_contains function.Outputstring(23) "Tutorial has been found"Example: str_contains function.Note: The above program returns false because the first string does not contain the second string.strpos() functionIn PHP 7.x, strops() function is used to check if a given string contains another string or not. This function returns ... Read More
315 Views
Weak Maps were added in PHP 7.4. It can be used to remove or delete objects when the cache refers to objects entity classes. It references to those objects, which does not avoid objects from memory garbage collected. In PHP 8, weak maps allow us to store random data linked to objects, without leaking any memory.In other words, a weak map in PHP 8 is a group of objects in which keys weakly reference. A weak map uses a class to create an object which can be used as a key, which can help to remove and destroy the weak ... Read More