Debug and Log PHP Opcache Issues

AmitDiwan
Updated on 27-Dec-2019 08:15:34

507 Views

The OPCache can be temporarily disabled by adding the below code to the script−ini_set('opcache.enable', 0);This can be used to tell whether OPCache was the reason behind the script failing. Due to this, the user will not have to go through every extension and turn them on/off to see which extension caused the issue.Finding the log that shows which file and what was the reason behind the script failing (when OPCache is enabled).If the user has more information about the application they are trying to debug, this is a feasible option to work on.ini_set('display_errors', 1); error_reporting(~0); If the above two solutions ... Read More

Creating Anonymous Objects in PHP

AmitDiwan
Updated on 27-Dec-2019 08:14:17

607 Views

Beginning from PHP version 7, it has been made possible to create anonymous classes. Every object in PHP is associated with a class. The anonymous classes can be instantiated to create objects.Example Live DemoOutputDoes the instance belong to parent class? = bool(true)In the above code, a parent class (my_sample_class) has been created, and it has been instantiated with a child class (new class) that inherits from the parent class.We are checking if the instance belongs to the parent class. Since the child class is an extension of the parent class, it returns True as output.

Set Encoding in PHP FPDI Library

AmitDiwan
Updated on 27-Dec-2019 08:13:21

911 Views

Below is the same code to set encoding for FPDI library−Add new fonts that have the correct alphabets.$pdf->AddFont('DejaVu', '', 'DejaVuSansCondensed.php'); $pdf->SetFont('DejaVu', '', 10, '', false);The following are three possible encodings that are possible.cp1250 (Central Europe) cp1251 (Cyrillic) cp1252 (Western Europe) cp1253 (Greek) cp1254 (Turkish) cp1255 (Hebrew) cp1257 (Baltic) cp1258 (Vietnamese) cp874 (Thai) or ISO-8859-1 (Western Europe) ISO-8859-2 (Central Europe) ISO-8859-4 (Baltic) ISO-8859-5 (Cyrillic) ISO-8859-7 (Greek) ISO-8859-9 (Turkish) ISO-8859-11 (Thai) ISO-8859-15 (Western Europe) ISO-8859-16 (Central Europe) Or KOI8-R (Russian) KOI8-U (Ukrainian)Let us see an example to convert the UTF-8 to cp1250.$str = iconv('UTF-8', 'cp1250', 'zazółcić gęślą jaźń');Note− If the string sent ... Read More

Difference Between array_merge and Array Plus Array in PHP

AmitDiwan
Updated on 27-Dec-2019 08:10:00

213 Views

Both get the union of arrays, but array_merge() overwrites duplicate non_numeric keys. Let us now see an example of the array+array−Example Live DemoOutputThis will produce the following output−array(8) {    ["p"]=>    string(3) "150"    ["q"]=>    string(3) "100"    ["r"]=>    string(3) "120"    ["s"]=>    string(3) "110"    ["t"]=>    string(3) "115"    ["u"]=>    string(3) "103"    ["v"]=>    string(3) "105"    ["w"]=>    string(3) "125" }ExampleLet us now see an example of array_merge() in PHP− Live DemoOutputThis will produce the following output−array(8) {    ["p"]=>    string(3) "150"    ["q"]=>    string(3) "100"    ["r"]=>    string(3) "120"    ["s"]=>    string(3) "110"    ["t"]=>    string(3) "115"    ["u"]=>    string(3) "110"    ["v"]=>    string(3) "105"    ["w"]=>    string(3) "100" }

Return All Dates Between Two Dates in an Array in PHP

AmitDiwan
Updated on 27-Dec-2019 08:04:44

3K+ Views

To return all dates between two dates, the code is as follows −Example Live DemoOutputThis will produce the following output−array(11) {    [0]=>    string(10) "10-11-2019"    [1]=>    string(10) "11-11-2019"    [2]=>    string(10) "12-11-2019"    [3]=>    string(10) "13-11-2019"    [4]=>    string(10) "14-11-2019"    [5]=>    string(10) "15-11-2019"    [6]=>    string(10) "16-11-2019"    [7]=>    string(10) "17-11-2019"    [8]=>    string(10) "18-11-2019"    [9]=>    string(10) "19-11-2019"    [10]=>    string(10) "20-11-2019" }

Reset Keys of Array Elements Using PHP

AmitDiwan
Updated on 27-Dec-2019 08:00:05

3K+ Views

To reset keys of array elements using PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−array(4) {    ["p"]=>    string(3) "150"    ["q"]=>    string(3) "100"    ["r"]=>    string(3) "120"    ["s"]=>    string(3) "110" } array(4) {    [0]=>    string(3) "150"    [1]=>    string(3) "100"    [2]=>    string(3) "120"    [3]=>    string(3) "110" }ExampleLet us now see another example − Live DemoOutputThis will produce the following output−array(4) {    [8]=>    string(3) "Ben"    [4]=>    string(5) "Kevin"    [7]=>    string(4) "Mark"    [3]=>    string(5) "Hanks" } array(4) {    [0]=>    string(3) "Ben"    [1]=>    string(5) "Kevin"    [2]=>    string(4) "Mark"    [3]=>    string(5) "Hanks" }

Remove First Character of String in PHP

AmitDiwan
Updated on 27-Dec-2019 07:53:32

2K+ Views

To remove the first character of a string in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output −Before removing the first character = Test After removing the first character = estExampleLet us now see another example Live DemoOutputThis will produce the following output−Before removing the first character = Demo After removing the first character = emo

Remove Array Element and Re-index in PHP

AmitDiwan
Updated on 27-Dec-2019 07:49:34

274 Views

To remove an array element and re-index the array, the code is as follows−Example Live DemoOutputThis will produce the following output−Array with leading and trailing whitespaces... Value = John Value = Jacob Value = Tom Value = Tim Comma separated list... John , Jacob , Tom , Tim Updated Array... Value = John Value = Jacob Value = Tom Value = Tim Updated Array...Re-indexed Value = John Value = Tom Value = Tim

Remove New Lines from String in PHP

AmitDiwan
Updated on 27-Dec-2019 07:47:05

688 Views

To remove newlines from the string, the code is as follows−Example Live DemoOutputThis will produce the following output−Demo     text for reference Demo text for referenceExampleLet us now see another example − Live DemoOutputThis will produce the following output−Demo     text Demo text

Get Parameters from a URL String in PHP

AmitDiwan
Updated on 27-Dec-2019 07:42:54

5K+ Views

To get parameters from a URL string in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−Email = example12@domain.comExampleLet us now see another example − Live DemoOutputThis will produce the following output−Email = demo

Advertisements