How to import a product programmatically in magento 2

Solution for : How to import a product programmatically in Magento 2

Below is the simple example fo achieve the solution:

use Magento\Framework\App\Bootstrap;

include("../app/bootstrap.php");
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');

$simpleProduct = $objectManager->create('\Magento\Catalog\Model\Product');
$simpleProduct->setSku('Testing3');
$simpleProduct->setName('Testing3');
$simpleProduct->setAttributeSetId(9);
$simpleProduct->setCategoryIds(3);
$simpleProduct->setDescription('This is for testing');
$simpleProduct->setStatus(1);
$simpleProduct->setTypeId('simple');
$simpleProduct->setPrice(500);
$simpleProduct->setWebsiteIds(array(1));
$simpleProduct->setVisibility(4);
$simpleProduct->setUrlKey('Testing3');

$simpleProduct->setStockData(array(
    'is_in_stock' => 1, //Stock Availability
    'qty' => 100//qty
        )
);

$attr = $simpleProduct->getResource()->getAttribute('color');
$attributeOptionId = $attr->getSource()->getOptionId('Red'); //name in Default Store View
$simpleProduct->setData('color', $attributeOptionId);

$simpleProduct->save();
$simpleProductId = $simpleProduct->getId();
echo "Simple Product ID: " . $simpleProductId . "\n";

How to calculate minute difference between two date-times in PHP?

Solution for : How to calculate minute difference between two date-times in PHP?

Below is the simple example fo achieve the solution:

$to_time = strtotime("2008-12-13 10:42:00");
$from_time = strtotime("2008-12-13 10:21:00");
echo round(abs($to_time - $from_time) / 60,2). " minute";

How to read if a checkbox is checked in PHP?

Solution for :How to read if a checkbox is checked in PHP?

If our HTML page looks like this:


After submitting the form we can check it with:

isset($_POST['checkbox1'])

OR

if ($_POST['checkbox1'] == 'value1'){ 

//I am checked.

}

Test if number is odd or even in php

Solution for : What is the simplest most basic way to find out if a number/variable is odd or even in PHP? Is it something to do with mod?

You were right in thinking mod was a good place to start. Here is an expression which will return true if $number is even, false if odd:

$number % 2 == 0

Example:

$number = 20;
if ($number % 2 == 0) {
  print "I am even";
}

Output:

I am even

How to find and replace text in a MySQL database

Solution for : How to find and replace text in a MySQL database

I have a column containing urls (id, url):

http://www.example.com/articles/updates/123
http://www.example.com/articles/updates/345
http://www.example.com/articles/updates/234

I'd like to change the word "updates" to "events". Is it possible to do this with a script?

QUERY: We can achieve the above requirements using below query.

UPDATE your_table
SET your_field = REPLACE(your_field, 'articles/updates/', 'articles/events/')
WHERE your_field LIKE '%articles/updates/%'

Find duplicate records in MySQL

Solution for :I want to pull out duplicate records in a MySQL Database.

The key is to rewrite this query so that it can be used as a sub-query.

EXAMPLE QUERY:

SELECT firstname, 
   lastname, 
   list.address 
FROM list
   INNER JOIN (SELECT address
               FROM   list
               GROUP  BY address
               HAVING COUNT(id) > 1) dup
           ON list.address = dup.address;

How to find all the tables in MySQL with specific column names in them?

Solution for :How to find all the tables in MySQL with specific column names in them?

To get all tables with columns columnA or ColumnB in the database YourDatabase:

QUERY:

SELECT DISTINCT TABLE_NAME 
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE COLUMN_NAME IN ('columnA','ColumnB')
        AND TABLE_SCHEMA='YourDatabase';

Insert into a MySQL table or update if exists

Solution for :Insert into a MySQL table or update if exists

If I want to add a row to a database table, but if a row exists with the same unique key I want to update the row.

For example:

insert into table (id, name, age) values(1, "A", 20)

Let’s say the unique key is id, and in my database there is a row with id = 1. In that case I want to update that row with these values. Normally this gives an error. If I use insert IGNORE it will ignore the error, but it still won’t update.

We can use INSERT ... ON DUPLICATE KEY UPDATE

QUERY:

INSERT INTO table (id, name, age) VALUES(1, "A", 20) ON DUPLICATE KEY UPDATE    
name="A", age=20

How to output MySQL query results in CSV format?

Solution for :Is there an easy way to run a MySQL query from the Linux command line and output the results in CSV format?

SELECT order_id,product_name,qty
FROM orders
WHERE foo = 'bar'
INTO OUTFILE '/var/lib/mysql-files/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';

Using this command columns names will not be exported.

Also note that /var/lib/mysql-files/orders.csv will be on the server that is running MySQL. The user that the MySQL process is running under must have permissions to write to the directory chosen, or the command will fail.

If you want to write output to your local machine from a remote server (especially a hosted or virtualize machine such as Heroku or Amazon RDS), this solution is not suitable.

jQuery Ajax POST example with PHP

Solution for : jQuery Ajax POST example with PHP

I would like to share a detailed way of how to post with PHP + Ajax along with errors thrown back on failure.

First of all, create two files, for example form.php and process.php.

We will first create a form which will be then submitted using the jQuery .ajax() method. The rest will be explained in the comments.

form.php

Validate the form using jQuery client-side validation and pass the data to process.php.

$(document).ready(function() {
    $('form').submit(function(event) { //Trigger on form submit
        $('#name + .throw_error').empty(); //Clear the messages first
        $('#success').empty();

        //Validate fields if required using jQuery

        var postForm = { //Fetch form data
            'name'     : $('input[name=name]').val() //Store name fields value
        };

        $.ajax({ //Process the form using $.ajax()
            type      : 'POST', //Method type
            url       : 'process.php', //Your form processing file URL
            data      : postForm, //Forms name
            dataType  : 'json',
            success   : function(data) {
                            if (!data.success) { //If fails
                                if (data.errors.name) { //Returned if any error from process.php
                                    $('.throw_error').fadeIn(1000).html(data.errors.name); //Throw relevant error
                                }
                            }
                            else {
                                    $('#success').fadeIn(1000).append('

' + data.posted + '

'); //If successful, than throw a success message } } }); event.preventDefault(); //Prevent the default submit }); });

Now we will take a look at process.php

$errors = array(); //To store errors
$form_data = array(); //Pass back the data to `form.php`

/* Validate the form on the server side */
if (empty($_POST['name'])) { //Name cannot be empty
    $errors['name'] = 'Name cannot be blank';
}

if (!empty($errors)) { //If errors in validation
    $form_data['success'] = false;
    $form_data['errors']  = $errors;
}
else { //If not, process the form, and return true on success
    $form_data['success'] = true;
    $form_data['posted'] = 'Data Was Posted Successfully';
}

//Return the data back to form.php
echo json_encode($form_data);

How to calculate the difference between two dates using PHP?

Solution for : How to calculate the difference between two dates using PHP?

I suggest to use DateTime and DateInterval objects.

$date1 = new DateTime("2007-03-24");
$date2 = new DateTime("2009-06-26");
$interval = $date1->diff($date2);
echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days "; 

// shows the total amount of days (not divided into years, months and days like above)
echo "difference " . $interval->days . " days ";

read more php DateTime::diff manual

From the manual:

As of PHP 5.2.2, DateTime objects can be compared using comparison operators.

$date1 = new DateTime("now");
$date2 = new DateTime("tomorrow");

var_dump($date1 == $date2); // bool(false)
var_dump($date1 < $date2);  // bool(true)
var_dump($date1 > $date2);  // bool(false)

Returning JSON from a PHP Script: A Quick Guide

JSON (JavaScript Object Notation) has become the standard format for exchanging data between clients and servers. If you're working with PHP, returning JSON from your script is straightforward and incredibly useful for building APIs or handling AJAX requests.

Why Use JSON?

  • Lightweight and easy to read
  • Natively supported by JavaScript
  • Ideal for client-server communication

How to Return JSON in PHP

Here’s a step-by-step guide:

1. Set the Content-Type Header

To ensure the response is treated as JSON, use:

header('Content-Type: application/json');

2. Create Your Data

Build an associative array or object to hold your data:

$data = [
    "status" => "success",
    "message" => "Data retrieved successfully",
    "data" => [1, 2, 3, 4]
];

3. Convert to JSON

Use json_encode() to convert your PHP data into a JSON string:

echo json_encode($data);

Example Script

Here’s a complete example:

 "success",
    "message" => "This is your JSON response!",
    "items" => ["item1", "item2", "item3"]
];

// Return JSON
echo json_encode($data);
?>

Error Handling

Always check for encoding errors:

 "JSON encoding failed"]);
}

?>

Testing Your Script

  • Use tools like Postman to test your script.
  • For a quick check, call your PHP script via AJAX or in the browser.

With this guide, you can start building JSON-based APIs and create seamless client-server integrations. For more tips, check out See Coding Blog!!

Getting product Image url in Magento 2

Solution for : Getting product Image url in Magento 2.

We can get using below simple lines:

 
$imagehelper = $objectManager->create('Magento\Catalog\Helper\Image');
$image = $imagehelper->init($_product,'category_page_list')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(400)->getUrl();

echo '';

Some useful MySQL DATABASE interview questions

How do you start MySQL on Linux?
- /etc/init.d/mysql start

How do you start and stop MySQL on Windows?
net start MySQL, net stop MySQL
What’s the default port for MySQL Server?
3306
 
What does tee command do in MySQL?
 tee followed by a filename turns on MySQL logging to a specified file. It can be stopped by command notee.
 
Can you save your connection settings to a conf file?
Yes, and name it ~/.my.conf. You might want to change the permissions on the file to 600, so that it’s not readable by others.
 
Have you ever used MySQL Administrator and MySQL Query Browser? Describe the tasks you accomplished with these tools.
 
What are some good ideas regarding user security in MySQL?
There is no user without a password. There is no user without a user name. There is no user whose Host column contains % (which here indicates that the user can log in from anywhere in the network or the Internet). There are as few users as possible (in the ideal case only root) who have unrestricted access.
 
How do you change a password for an existing user via mysqladmin?
mysqladmin -u root -p password "newpassword"
 
Explain the difference between MyISAM Static and MyISAM Dynamic.
In MyISAM static all the fields have fixed width. The Dynamic MyISAM table would include fields such as TEXT, BLOB, etc. to accommodate the data types with various lengths. MyISAM Static would be easier to restore in case of corruption, since even though you might lose some data, you know exactly where to look for the beginning of the next record.
 
What does myisamchk do?
It compressed the MyISAM tables, which reduces their disk usage.
 
Explain advantages of InnoDB over MyISAM?
Row-level locking, transactions, foreign key constraints and crash recovery.
 
Explain advantages of MyISAM over InnoDB?
Much more conservative approach to disk space management - each MyISAM table is stored in a separate file, which could be compressed then with myisamchk if needed. With InnoDB the tables are stored in tablespace, and not much further optimization is possible. All data except for TEXT and BLOB can occupy 8,000 bytes at most. No full text indexing is available for InnoDB. TRhe COUNT(*)s execute slower than in MyISAM due to tablespace complexity.
 
What are HEAP tables in MySQL?
HEAP tables are in-memory. They are usually used for high-speed temporary storage. No TEXT or BLOB fields are allowed within HEAP tables. You can only use the comparison operators = and <=>. HEAP tables do not support AUTO_INCREMENT. Indexes must be NOT NULL.
 
How do you control the max size of a HEAP table?
MySQL config variable max_heap_table_size.
 
Explain the difference between mysql and mysqli interfaces in PHP?
mysqli is the object-oriented version of mysql library functions.
 
What are CSV tables?
Those are the special tables, data for which is saved into comma-separated values files. They cannot be indexed.
 
Explain federated tables. - Introduced in MySQL 5.0, federated tables allow access to the tables located on other databases on other servers.
 
What is SERIAL data type in MySQL?
BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT
 
What happens when the column is set to AUTO INCREMENT and you reach the maximum value for that table?
It stops incrementing. It does not overflow to 0 to prevent data losses, but further inserts are going to produce an error, since the key has been used already.
 
Explain the difference between FLOAT, DOUBLE and REAL.
FLOATs store floating point numbers with 8 place accuracy and take up 4 bytes. DOUBLEs store floating point numbers with 16 place accuracy and take up 8 bytes. REAL is a synonym of FLOAT for now.
 
If you specify the data type as DECIMAL (5,2), what’s the range of values that can go in this table? - 999.99 to -99.99. Note that with the negative number the minus sign is considered one of the digits.
 
Use mysqldump to create a copy of the database?
 mysqldump -h mysqlhost -u username -p mydatabasename > dbdump.sql
 
What happens if a table has one column defined as TIMESTAMP? 
That field gets the current timestamp whenever the row gets altered.
 
But what if you really want to store the timestamp data, such as the publication date of the article? Create two columns of type TIMESTAMP and use the second one for your real data.
 
Explain the difference between BOOL, TINYINT and BIT.
Prior to MySQL 5.0.3: those are all synonyms. After MySQL 5.0.3: BIT data type can store 8 bytes of data and should be used for binary data.
 

PHP interview Questions ( basics )

  1. What is PHP?
    PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and cms for creating websites.Even a non technical person can cretae sites using its CMS.WordPress,osCommerce are the famus CMS of php.It is also an object oriented programming language like java,C-sharp etc.It is very eazy for learning

  2. What is the use of "echo" in php?
    It is used to print a data in the webpage, Example:
     echo 'Car insurance';  
    The following code print the text in the webpage

  3. How to include a file to a php page?
    We can include a file using include() " or "require()" function with file path as its parameter.

  4. What's the difference between include and require?
    If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

  5. require_once(), require(), include(). What is difference between them?
    require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.

  6. Differences between GET and POST methods ?
    We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than GET method .

  7. How to declare an array in php?
    Eg :
     var $arr = array('apple', 'grape', 'lemon');

  8. What is the use of 'print' in php?
    This is not actually a real function, It is a language construct. So you can use with out parentheses with its argument list.

    Example
    print('PHP Interview questions');
     print 'Job Interview ');

  9. What is use of in_array() function in php ?
    in_array used to checks if a value exists in an array

  10. What is use of count() function in php ?
    count() is used to count all elements in an array, or something in an object

  11. What’s the difference between include and require?
    It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

  12. What is the difference between Session and Cookie?
    The main difference between sessions and cookies is that sessions are stored on the server, and cookies are stored on the user’s computers in the text file format. Cookies can not hold multiple variables,But Session can hold multiple variables.We can set expiry for a cookie,The session only remains active as long as the browser is open.Users do not have access to the data you stored in Session,Since it is stored in the server.Session is mainly used for login/logout purpose while cookies using for user activity tracking

  13. How to set cookies in PHP?
    Setcookie("sample", "ram", time()+3600);

  14. How to Retrieve a Cookie Value?
    eg :
    echo $_COOKIE["user"];

  15. How to create a session? How to set a value in session ? How to Remove data from a session?
    Create session :
     session_start();
    Set value into session :
    $_SESSION['USER_ID']=1;
    Remove data from a session :
    unset($_SESSION['USER_ID'];

  16. what types of loops exist in php?
    for,while,do while and foreach (NB: You should learn its usage)

  17. How to create a mysql connection?
    mysql_connect(servername,username,password);

  18. How to select a database?
    mysql_select_db($db_name);

  19. How to execute an sql query? How to fetch its result ?
    $my_qry = mysql_query("SELECT * FROM `users` WHERE `u_id`='1'; "); 
    $result = mysql_fetch_array($my_qry);
    echo $result['First_name'];
    
  20. Write a program using while loop
    $my_qry = mysql_query("SELECT * FROM `users` WHERE `u_id`='1'; "); 
    while($result = mysql_fetch_array($my_qry))
    {
    echo $result['First_name'.]."<br/>";
    }
    
  21. How we can retrieve the data in the result set of MySQL using PHP?
    • 1. mysql_fetch_row
    • 2. mysql_fetch_array
    • 3. mysql_fetch_object
    • 4. mysql_fetch_assoc 
  22. What is the use of explode() function ?
    Syntax : array explode ( string $delimiter , string $string [, int $limit ] );
    This function breaks a string into an array. Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.

  23. What is the difference between explode() and split() functions?
    Split function splits string into array by regular expression. Explode splits a string into array by string.

  24. What is the use of mysql_real_escape_string() function?
    It is used to escapes special characters in a string for use in an SQL statement

  25. Write down the code for save an uploaded file in php.
    f ($_FILES["file"]["error"] == 0)
    {
    move_uploaded_file($_FILES["file"]["tmp_name"],
          "upload/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    }
    
  26. How to create a text file in php?
    $filename = "/home/user/guest/newfile.txt";
    $file = fopen( $filename, "w" );
    if( $file == false )
    {
    echo ( "Error in opening new file" ); exit();
    }
    fwrite( $file, "This is a simple test\n" );
    fclose( $file );
    
  27. How to strip whitespace (or other characters) from the beginning and end of a string ?
    The trim() function removes whitespaces or other predefined characters from both sides of a string.

  28. What is the use of header() function in php ?
    The header() function sends a raw HTTP header to a client browser.Remember that this function must be called before sending the actual out put.For example, You do not print any HTML element before using this function.

  29. How to redirect a page in php?
    The following code can be used for it,
    header("Location:index.php");

     
  30. How stop the execution of a php scrip ?
    exit() function is used to stop the execution of a page

  31. How to set a page as a home page in a php based site ?
    index.php is the default name of the home page in php based sites

  32. How to find the length of a string?
    strlen() function used to find the length of a string

  33. what is the use of rand() in php?
    It is used to generate random numbers.If called without the arguments it returns a pseudo-random integer between 0 and getrandmax(). If you want a random number between 6 and 12 (inclusive), for example, use rand(6, 12).This function does not generate cryptographically safe values, and should not be used for cryptographic uses. If you want a cryptographically secure value, consider using openssl_random_pseudo_bytes() instead.

  34. what is the use of isset() in php?
    This function is used to determine if a variable is set and is not NULL

  35. What is the difference between mysql_fetch_array() and mysql_fetch_assoc() ?
    mysql_fetch_assoc function Fetch a result row as an associative array, While mysql_fetch_array() fetches an associative array, a numeric array, or both

  36. What is mean by an associative array?
    Associative arrays are arrays that use string keys is called associative arrays.

  37. What is the importance of "method" attribute in a html form?
    "method" attribute determines how to send the form-data into the server.There are two methods, get and post. The default method is get.This sends the form information by appending it on the URL.Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

  38. What is the importance of "action" attribute in a html form?
    The action attribute determines where to send the form-data in the form submission.

  39. What is the use of "enctype" attribute in a html form?
    The enctype attribute determines how the form-data should be encoded when submitting it to the server. We need to set enctype as "multipart/form-data" when we are using a form for uploading files

  40. How to create an array of a group of items inside an HTML form ?
    We can create input fields with same name for "name" attribute with squire bracket at the end of the name of the name attribute, It passes data as an array to PHP.
    For instance :
     
    
     
    
    
    
  41. Define Object-Oriented Methodology
    Object orientation is a software/Web development methodology that is based on the modeling a real world system.An object is the core concept involved in the object orientation. An object is the copy of the real world enity.An object oriented model is a collection of objects and its inter-relationships

  42. How do you define a constant?
    Using define() directive, like
     define ("MYCONSTANT",150)

  43. How send email using php?
    To send email using PHP, you use the mail() function.This mail() function accepts 5 parameters as follows (the last 2 are optional). You need webserver, you can't send email from localhost. eg :
     mail($to,$subject,$message,$headers); 
  44. How to find current date and time?
    The date() function provides you with a means of retrieving the current date and time, applying the format integer parameters indicated in your script to the timestamp provided or the current local time if no timestamp is given. In simplified terms, passing a time parameter is optional - if you don't, the current timestamp will be used.

  45. Difference between mysql_connect and mysql_pconnect?
    There is a good page in the php manual on the subject, in short mysql_pconnect() makes a persistent connection to the database which means a SQL link that do not close when the execution of your script ends. mysql_connect()provides only for the databasenewconnection while using mysql_pconnect , the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection... the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use.

  46. What is the use of "ksort" in php?
    It is used for sort an array by key in reverse order.

  47. What is the difference between $var and $$var?
    They are both variables. But $var is a variable with a fixed name. $$var is a variable who's name is stored in $var. For example, if $var contains "message", $$var is the same as $message.

  48. What are the encryption techniques in PHP
    MD5 PHP implements the MD5 hash algorithm using the md5 function,
    eg : $encrypted_text = md5 ($msg);
    mcrypt_encrypt :-
     string mcrypt_encrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] ); 
    Encrypts plaintext with given parameters

  49. What is the use of the function htmlentities?
    htmlentities Convert all applicable characters to HTML entities This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

  50. How to delete a file from the system
    Unlink() deletes the given file from the file system.

  51. How to get the value of current session id?
    session_id() function returns the session id for the current session.

  52. What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
    • Mysql_fetch_array Fetch a result row as an associative array, a numeric array, or both.
    • mysql_fetch_object ( resource result ) Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows
    • mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.
    •  
  53. What are the different types of errors in PHP ?
    Here are three basic types of runtime errors in PHP:
    • 1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although you can change this default behavior.
    • 2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
    • 3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when they take place.
  54. what is sql injection ?
    SQL injection is a malicious code injection technique.It exploiting SQL vulnerabilities in Web applications

  55. What is x+ mode in fopen() used for?
    Read/Write. Creates a new file. Returns FALSE and an error if file already exists

  56. How to find the position of the first occurrence of a substring in a string
    strpos() is used to find the position of the first occurrence of a substring in a string

  57. What is PEAR?
    PEAR is a framework and distribution system for reusable PHP components.The project seeks to provide a structured library of code, maintain a system for distributing code and for managing code packages, and promote a standard coding style.PEAR is broken into three classes: PEAR Core Components, PEAR Packages, and PECL Packages. The Core Components include the base classes of PEAR and PEAR_Error, along with database, HTTP, logging, and e-mailing functions. The PEAR Packages include functionality providing for authentication, networking, and file system features, as well as tools for working with XML and HTML templates.

  58. Distinguish between urlencode and urldecode?
    This method is best when encode a string to used in a query part of a url. it returns a string in which all non-alphanumeric characters except -_. have replece with a percentege(%) sign . the urldecode->Decodes url to encode string as any %and other symbole are decode by the use of the urldecode() function.

  59. What are the different errors in PHP?
    In PHP, there are three types of runtime errors, they are:
    Warnings:
    These are important errors. Example: When we try to include () file which is not available. These errors are showed to the user by default but they will not result in ending the script.
    Notices:
    These errors are non-critical and trivial errors that come across while executing the script in PHP. Example: trying to gain access the variable which is not defined. These errors are not showed to the users by default even if the default behavior is changed.
    Fatal errors:
    These are critical errors. Example: instantiating an object of a class which does not exist or a non-existent function is called. These errors results in termination of the script immediately and default behavior of PHP is shown to them when they take place. Twelve different error types are used to represent these variations internally.