How can we extract string "abc.com" from a string "https://info@abc.com" using regular _expression of php?
Correct Answer
We can use the preg_match() function with ?/*@(*)$/? as the regular expression pattern For example: preg_match("/*@(*)$/","https://info@abccom",$data); echo $data[1]; ?>
Technology problems
Search Results
1. Explain include(), include_once, require() and require_once.
Correct Answer: include() The include() function takes all the content in a specified file and includes it in the current file If an error occurs, the include() function generates a warning, but the script will continue execution include_once() File will not be included more than once If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once() require() The require() function is identical to include(), except that it handles errors differently The require() generates a fatal error, and the script will stop require_once() The required file is called only once when a page is open and further calling of the file will be ignored
2. How do you destroy a particular or all Sessions?
Correct Answer: A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor
4. What are the differences between GET and POST methods in form submitting?
Correct Answer: On the server side, the main difference between GET and POST is where the submitted is stored The $_GET array stores data submitted by the GET method The $_POST array stores data submitted by the POST method On the browser side, the difference is that data submitted by the GET method will be displayed in the browser?s address field Data submitted by the POST method will not be displayed anywhere on the browser GET method is mostly used for submitting a small amount and less sensitive data POST method is mostly used for submitting a large amount or sensitive data
5. What is the functionality of md5 function in PHP?
Correct Answer: Calculate the md5 hash of a string The hash is a 32-character hexadecimal number I use it to generate keys which I use to identify users etc If I add random no techniques to it the md5 generated now will be totally different for the same string I am using
Correct Answer: 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, as you will see, you can change this default behaviour 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 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 behaviour is to display them to the user when they take place
7. What is the functionality of the function strstr and stristr?
Correct Answer: strstr() returns part of a given string from the first occurrence of a given substring to the end of the string For example: strstr("user@examplecom","@") will return "@examplecom" stristr() is idential to strstr() except that it is case insensitive
8. What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
Correct Answer: mysql_fetch_array: Fetch a result row as an associative array and a numeric array mysql_fetch_object: 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
Correct Answer: setcookie('variable','value','time'); variable - name of the cookie variable value - value of the cookie variable time - expiry time Example: Test - cookie variable name $i - value of the variable 'Test' time()+3600 - denotes that the cookie will expire after an one hour