Difference Between isset and empty in PHP

AmitDiwan
Updated on 07-Apr-2020 11:56:02

921 Views

Isset functionISSET checks the variable to see if it has been set. In other words, it checks to see if the variable is any value except NULL or not assigned a value. ISSET returns TRUE if the variable exists and has a value other than NULL. That means variables assigned a "", 0, "0", or FALSE are set, and therefore are TRUE for ISSET.Example Live DemoOutputThis will produce the following output −0 is set with isset function array is not set.!empty functionEMPTY checks to see if a variable is empty. Empty is interpreted as: "" (an empty string), 0 (integer), 0.0 ... Read More

Remove Numbers After Hyphen in Varchar String with MySQL Query

AmitDiwan
Updated on 07-Apr-2020 11:54:11

557 Views

For this, use SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable2040    -> (    -> StudentCode varchar(20)    -> ); Query OK, 0 rows affected (0.85 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2040 values('John-232'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2040 values('Carol-901'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable2040 values('David-987'); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable2040;This will produce the following output −+-------------+ | StudentCode | +-------------+ | ... Read More

Detect Client Locale in PHP

AmitDiwan
Updated on 07-Apr-2020 11:52:30

1K+ Views

PHP provides a function beginning from 5.3.0 to parse the ‘$_SERVER['HTTP_ACCEPT_LANGUAGE']’ variable into a locale −Example$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); echo $locale;The ‘$_SERVER['HTTP_ACCEPT_LANGUAGE']’ function helps detect the locale by taking the current locale’s language as the parameter.OutputThis will produce the following output −en_USMost browsers submit an Accept-Language HTTP header that specifies en-us if they are from the US. Some older browsers use en only.English-UK based users usually set their system or user locale to English-UK, which is the default browser configuration. This would result in en-gb as the Accept Language header. Other countries have en locales, such as en-za (South Africa), and ... Read More

Display Records in Ascending Order with MySQL

AmitDiwan
Updated on 07-Apr-2020 11:52:28

161 Views

To display a list of records in a specific order, you need to set conditions and use ORDER BY. For this, use ORDER BY CASE statement. Let us first create a table −mysql> create table DemoTable2039    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2039 values('John Doe'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable2039 values('John Smith'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable2039 values('Chris Brown'); Query OK, 1 row affected ... Read More

MySQL Query to Return True for Rows Having Positive Value

AmitDiwan
Updated on 07-Apr-2020 11:51:39

270 Views

To return TRUE for positive values and FALSE for negative, use MySQL IF(). Let us first create a table −mysql> create table DemoTable2038    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Value int    -> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2038(Value) values(57); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable2038(Value) values(-100);; Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2038(Value) values(-78); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable2038(Value) ... Read More

Reading and Writing a MS Word File in PHP

AmitDiwan
Updated on 07-Apr-2020 11:50:09

648 Views

Microsoft strongly advises not to use the automation of Office documents via COM objects. It quotes the following −“Microsoft does not currently recommend or support the Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.”A .docx file can be created without COM objects since it has XML foundations (PHPDOCX could be used for this). An added advantage of this method is that a local copy of Word that was installed wouldn’t have to be created ... Read More

Recreate and Display an Image from Binary Data in PHP

AmitDiwan
Updated on 07-Apr-2020 11:48:20

2K+ Views

This can be done using data URI in the image src attribute.Formatdata:[][;charset=""][;base64],

URL Decoding in PHP

AmitDiwan
Updated on 07-Apr-2020 11:45:18

549 Views

URL decoding can be done using the built-in 'urldecode' function. This returns the encoded data.Syntax of urldecode functionstring urldecode($input)It takes a single parameter ($input) which is the URL that is to be decoded. Returns the decoded string provided the decoding was successful −Example Live Demo In the above lines of the code, the ‘urldecode’ function takes in the raw (encoded string) and returns the decoded value of the string.OutputThis will produce the following output −https://medium.com/

Convert ASCII to UTF-8 Encoding in PHP

AmitDiwan
Updated on 07-Apr-2020 11:43:58

8K+ Views

If we know that the current encoding is ASCII, the 'iconv' function can be used to convert ASCII to UTF-8. The original string can be passed as a parameter to the iconv function to encode it to UTF-8.Example Live DemoA string with special characters is assigned to ‘str’ variable. This is passed to the ‘iconv’ function, with the encoding that it currently is in, and the encoding to which it needs to be converted to.OutputThis will produce the following output −Original :ábrêcWtë Plain :�br�cWt�Another method is to detect the encoding and then converting it to an appropriate encoding −Example Live Demo$string = ... Read More

Fetch First Letter of a Column Value and Insert It in Another Column with MySQL

AmitDiwan
Updated on 07-Apr-2020 11:41:05

455 Views

For this, use the concept of LEFT() function. Let us first create a table −mysql> create table DemoTable2036    -> (    -> FirstLetter varchar(20),    -> Title varchar(20)    -> ); Query OK, 0 rows affected (1.01 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2036(Title) values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2036(Title) values('John'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable2036(Title) values('Adam'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable2036;This will produce the ... Read More

Advertisements