Found 1060 Articles for PHP

Can HTML be embedded inside PHP “if” statement?

AmitDiwan
Updated on 06-Apr-2020 07:27:27

6K+ Views

Yes, HTML can be embedded inside an ‘if’ statement with the help of PHP. Below are a few methods.Using the if condition −    it is displayed iff $condition is met Using the if and else if conditions −     it is displayed iff $condition is met    HTML TAG HERE    HTML TAG HERE Embedding HTML inside PHP − HTML TAG HERE

How to detect search engine bots with PHP?

AmitDiwan
Updated on 06-Apr-2020 07:21:13

1K+ Views

A search engine directory of the spider names can be used as a reference. Next, $_SERVER['HTTP_USER_AGENT']; can be used to check if the agent is a spider (bot).Below is an example demonstrating the same −if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "some_bot_name")) {    //other steps that need to be used }Code explanation − The agent, along with the user agent is passed to the strtolower function, whose output in turn is passed to the strstr function. Both the user agent and the bot are compared to see if the spider is a bot or not.Another option is shown below −function _bot_detected() {    return (   ... Read More

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

AmitDiwan
Updated on 06-Apr-2020 07:06:10

910 Views

Yes, an object can be instantiated and a method can be called on a single line using PHP. This feature has come into effect beginning from PHP version 5.4.An object can be instantiated by accessing the class member of the class. This can be seen in the below snippet −(new my_var)-> my_instance()Code explanation − Here, my_instance is the method and my_var is the object that needs to be instantiated.Example Live Democlass Test_class {    public function __construct($param) {       $this->_var = $param;    }    public function my_method() {       return $this->_var * 2;    }   ... Read More

Print newline in PHP in single quotes

AmitDiwan
Updated on 06-Apr-2020 07:03:11

636 Views

Since can’t be used with single quotes, we need to resort to other options.When using command line interface, the constant PHP_EOL can be used.When using with browsers, the ‘’ can be used.Both the options have been demonstrated below.Suppose our option was not cli, the ‘else’ part will be executed and a newline will be printed −Example Live DemoOutputThis will produce the following output −hi hello hihello

How can I break an outer loop with PHP?

AmitDiwan
Updated on 06-Apr-2020 06:59:59

234 Views

If there are two nested loops, the break statement can be used −break 2;Below is a demonstration with the foreach loop −foreach(...) {    foreach(...) {       if (my_var_1.name == my_var_2)       break 2; //it breaks out of the outermost foreach loop    } }For PHP version>=5.3, the below lines of code can be used −foreach (...) {    foreach (...) {       if (my_var_1.name == my_var_2)       goto top;    } } top:

Migrating PHP 5.x to PHP 7 on CentOS 7

Samual Sam
Updated on 22-Jan-2020 08:14:19

486 Views

In this article, we will learn about how to upgrade and update PHP 5.x to PHP 7, PHP 7 which was released in 2015 with speed improvements comparable to the older versions of the PHP.PrerequisitesAssuming that we have already installed PHP 5.x on CentOS7, and mod_php module should be enabled by Apache, and we need Sudo privileges or root user.Enabling the PHP 7 RepositoryAs PHP 7.x is not available in the official repositories, so we need to use IUS community Project Repository.Download the IUS repository in the machine with the below command# 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
Updated on 22-Jan-2020 06:58:20

591 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”.Before installing PHP7, you should need to install a PPA called ondrej/php. This allows you to co-install PHP versions 5.6 and 7.0.Configuring a PPA for co-installable PHP 5.6 + 7.0To configure a PPA, use ... Read More

Review of Magento Platform – Content Management System

Sharon Christine
Updated on 17-Jan-2020 12:29:43

215 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 of 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.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 of merchandising to ... Read More

Difference between the and$ operator in php

Mahesh Parahar
Updated on 13-Jan-2020 06:43:02

495 Views

$ operatorOperator is used to define variables in php. For example, message. Such variables can contain any type of value like int, string, etc.$$ operator$$ is a special operator that contains the name of another variable and can be used to access the value of that variable.ExampleFollowing the example, shows the usage of '′vs′$' operators. Live Demo    PHP Example     Outputmessage Welcome to Tutorialspoint

Difference between the AND and && operator in php

Mahesh Parahar
Updated on 13-Jan-2020 06:39:02

429 Views

'AND' Logical operator'AND' operator is a logical AND operator but has low precedence to = operator.'&&' Logical operator'&&' is also a logical AND operator but has high precedence to = operator.ExampleFollowing the example, shows the difference of 'AND' vs '&&' operators. Live Demo    PHP Example     Output$result = $x AND $y bool(true) $result = $x && $y bool(false)

Advertisements