PHP Articles

Page 55 of 81

In PHP, can you instantiate an object and call a method on the same line?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 972 Views

Yes, in PHP you can instantiate an object and call a method on the same line. This feature is available starting from PHP 5.4 and is called "object dereferencing" or "method chaining on instantiation". Syntax The basic syntax for instantiating and calling a method on the same line is ? (new ClassName())->methodName() The parentheses around new ClassName() are required to ensure proper parsing. Example Here's a practical example demonstrating object instantiation and method calling on a single line ? Result: 15 Hello World Key ...

Read More

Print newline in PHP in single quotes

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 717 Views

In PHP, the newline character doesn't work inside single quotes because single quotes treat all characters literally. However, there are several alternative approaches to print newlines when working with single quotes. Using PHP_EOL Constant The PHP_EOL constant provides a cross−platform newline character that works in both CLI and web environments ? First line Second line Using Double Quotes for Newline You can combine single quotes with double−quoted newline characters ? Hello World Using chr() Function The chr(10) function returns ...

Read More

How can I break an outer loop with PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 286 Views

In PHP, you can break out of an outer loop from within nested loops using the break statement with a numeric parameter or the goto statement. This is useful when you need to exit multiple loop levels at once. Using break with Numeric Parameter The break statement accepts an optional numeric parameter that specifies how many nested loops to break out of − Outer loop: 1 Inner loop: 1 Inner loop: 2 Inner loop: 3 Outer loop: 2 Inner loop: 1 Inner ...

Read More

Migrating PHP 5.x to PHP 7 on CentOS 7

Samual Sam
Samual Sam
Updated on 15-Mar-2026 545 Views

In this article, we will learn how to upgrade PHP 5.x to PHP 7 on CentOS 7. PHP 7, released in 2015, offers significant performance improvements over previous PHP versions. Prerequisites You need PHP 5.x already installed on CentOS 7 with mod_php enabled in Apache, plus sudo privileges or root access. Enabling the PHP 7 Repository Since PHP 7.x is not available in official CentOS repositories, we'll use the IUS Community Project Repository. Download the IUS repository setup script − # curl 'https://setup.ius.io/' -o setup-ius.sh curl 'https://setup.ius.io/' -o setup-ius.sh ...

Read More

How to Install PHP 7 on Ubuntu Linux 14.04 LTS

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 657 Views

PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. Originally created by Rasmus Lerdorf in 1994, the PHP reference implementation is now produced by The PHP Group. The latest version PHP is PHP7 and it provides 2x faster performance and 50% better memory consumption than PHP version 5.6. This article explains "How to install PHP7 on Ubuntu Linux". Prerequisites: Ubuntu 14.04 LTS system with sudo privileges and internet connection. Before installing PHP7, you should need to install a PPA called ondrej/php. This allows you to co-install PHP ...

Read More

Review of Magento Platform – Content Management System

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 282 Views

Magento is a fastest growing open source eCommerce platform that uses MySQL and Zend PHP databases. Magento is a very flexible eCommerce platform that facilitates powerful marketing, management of multiple websites, catalogue management, and integration with Google Website Optimizer and over 50 payment gateways. It gives the flexibility for the users to control the content, look and functionality of the ecommerce store. Magento was originally developed by Varien Inc., a US private company in California. Today, some of their largest users are Burger King, Nestle, Murad, BevMo, and Coca-Cola. Magento open source CMS platform provides increased control in terms ...

Read More

Performance of FOR vs FOREACH in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

The performance difference between for and foreach loops in PHP has been a topic of debate among developers. While foreach was historically slower due to array copying, modern PHP versions have optimized this significantly. Performance Comparison Let's compare the execution time of for vs foreach loops with a practical example − Output Foreach (copy): 0.0012 seconds Foreach (reference): 0.0008 seconds For loop: 0.0015 seconds For loop (optimized): 0.0009 seconds Key Performance Factors Loop Type Memory Usage Speed Best For foreach (by value) Higher (creates ...

Read More

Get all subdirectories of a given directory in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

To get the subdirectories present in a directory, PHP provides several methods. The glob() function with appropriate filters is the most common approach. Using glob() with is_dir Filter This method gets all items and filters them to return only directories ? Array ( [0] => documents [1] => images [2] => scripts [3] => templates ) Using glob() with GLOB_ONLYDIR Flag This is the most efficient method as it directly returns only directories ...

Read More

PHP Regex to get YouTube Video ID

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 836 Views

In PHP, you can extract YouTube video IDs from URLs using the parse_url() and parse_str() functions or regular expressions. The parsing approach is more reliable for standard YouTube URLs. Using parse_url() and parse_str() The most straightforward method uses built-in PHP functions to parse the URL query parameters − VX96I7PO8YU The parse_url() function extracts the query string, while parse_str() converts it into an associative array where the video ID is stored in the 'v' key. Using Regular Expression For more complex YouTube URL formats, regex provides better flexibility − ...

Read More

How to capture the result of var_dump to a string in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

In PHP, you can capture the result of var_dump() to a string using output buffering functions. This is useful when you need to store or manipulate the debug output instead of displaying it directly. Using Output Buffering The ob_start() and ob_get_clean() functions allow you to capture output that would normally be sent to the browser − array(3) { [0]=> string(5) "first" [1]=> string(6) "second" [2]=> string(5) "third" } How It Works The output buffering process works in ...

Read More
Showing 541–550 of 802 articles
« Prev 1 53 54 55 56 57 81 Next »
Advertisements