Ans: Java script applied on client side while in php code executed on server reviews side.
Q .In PHP how can you jump in to and out of “php mode”?
Ans: The Php code is enclosed in special Start < ? and end ? > tags that allow ingredients you to jump in to and out of “php mode”.
What does a special set of tags = and ?> do in PHP?
The tags <?= and ?> displayed output directly to the web browser.
How can we Calculate the similarity between two strings
Using similar_text() get similarity between two strings.
Return Values
Returns the number of matching chars in both strings.
example
<?php
$first =’php3′;
$first =’php4′;
echo retail price similar_text ( $first, $second ) //3
?>
Return ASCII value of character in php?
using ord() method we can get ASCII value of character in php.
<?php
$str = "\n" style="color: #007700;">;
if (ord style="color: #0000bb;">$str) == 10) {
echo "The first character of \$str is a line feed.\n";
}
?> How can we format a number as “22.00″ in php ?
using number_format() function.
<?php
$number = 1234.56;
// english notation (default)
$english_format_number = number_format( style=”color: #0000bb;”>$number);
// 1,235
// French notation
$nombre_format_francais style=”color: #007700;”>= number_format($number, 2, style=”color: #dd0000;”>’,’, ‘ ’);
// 1 234,56
$number = 1234.5678;
// english notation without thousands seperator
$english_format_number = number_formatviagra order style=”color: #007700;”>($number, 2, ‘.’, ”);
// 1234.57
?>
how can we insert HTML line breaks before all newlines in a string
using nl2br function
nl2br — Inserts HTML line breaks before all newlines in a string
n style="color: #000000;"><?php
style="color: #007700;">echo nl2br("foo isn't\n bar");
?>
The above example will output:
foo isn't<br /> bar
what does money_format() function in php?
money_format — Formats a number as a currency string
We will use different locales and format specifications to illustrate the use of this function.
<?php
$number = 1234.56;
// let’s print the international format for the en_US locale
style=”color: #0000bb;”>setlocale(LC_MONETARY, ‘en_US’);
echo money_format(‘%i’, $number) . “\n”;
// USD 1,234.56
// Italian national format with 2 decimals`
setlocale(LC_MONETARY, ‘it_IT’);
echo money_format(‘%.2n’, $number) . “\n”;
// L. 1.234,56
// Using a negative number
$number = -1234.5672;
// US national format, using () for negative numbers
// and 10 digits for left precision
setlocale(LC_MONETARY, ‘en_US’);
echo money_format(‘%(#10n’, $number) . “\n”;
// ($ 1,234.57)
// Similar format as above, adding the use of 2 digits of right
// precision and ’*' as a fill character
echo money_format(‘%=*(#10.2n’, $number) . “\n”;
// ($********1,234.57)
// Let’s justify to the left, with 14 positions of width, 8 digits of
// left precision, 2 of right precision, withouth grouping character
// and using the international format for the de_DE locale.
setlocale(LC_MONETARY, ‘de_DE’);
echo money_format(‘%=*^-14#8.2i’, 1234.56) . “\n”;
// DEM 1234,56****
// Let’s add some blurb before and after the conversion specification
style=”color:#0000bb;”>setlocale(LC_MONETARY, ‘en_GB’);
$fmt = ‘The final value is %i (after a 10%% discount)’;
echo money_format($fmt, 1234.56) . “\n”;
// The final value is GBP 1,234.56 (after a 10% discount)
?>
what is difference between explode and implode functions?
explode — Split a string by string
explode, split a string and return an array by using niddle in the string.
Example . explode()
<?php
// Example 1
$history= "php4 php5 php6";
$pieces = (" ", $history);
echo $history[0]; // php3
echo $history[1]; // php4
echo $history[1]; // php5
?>
implode — Join array elements with a string
Example: implode() example
<?php
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo $comma_separated; // lastname,email,phone
?> Count character in the string “Two Ts and one F.” in php ?
To count the total number of characters in the given string.
we will use count_chars() funtion
count_chars — Return information about characters used in a string
Return Values
Depending on mode count_chars() returns one of the following:
- 0 – an array with the byte-value as key and the frequency of every byte as value.
- 1 – same as 0 but only byte-values with a frequency greater than zero are listed.
- 2 – same as 0 but only byte-values with a frequency equal to zero are listed.
- 3 – a string containing all used byte-values cheapest is returned.
- 4 – a string containing all not used byte-values is returned.
<?php
$data = "Two Ts and one F.";
foreach (count_chars($data, 1) as $i => $val) {
echo “There were $val instance(s) of \”" , chr($i) , “\” in the string.\n”;
}
?> The above example will output:
There were 4 instance(s) of " " in the string. There were 1 instance(s) of "." in the string. There were 1 instance(s) of "F" in the string. There were 2 instance(s) of "T" in the string. There were 1 instance(s) of "a" in the string. There were 1 instance(s) of "d" in the string. There were 1 instance(s) of "e" in the string. There were 2 instance(s) of "n" in the string. There were 2 instance(s) of "o" in the string. There were 1 instance(s) of "s" in the string. There were 1 instance(s) of "w" in the string.
what is difference between addslashes() and addcslashes()
addslashes — Quote string with slashes
Returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote (‘), double quote (“), backslash (\) and NUL (the NULL byte).
style="color: #000000;"><?php
$str = "Is your name O'reilly?";
// Outputs: Is your name O\'reilly? echo addslashes($str style="color: #007700;">);
?>Returns a string with backslashes before characters that are listed in charlist parameter.
<?php
echo addcslashes("zoo['.']", 'z..A');
// output: \zoo['\.']
?>
what is addcslashes() in php?
addcslashes — Quote string with slashes in a C style
style="color: #0000bb;"><?php
addcslashes('foo[ ]', 'A..z');
// output: \f\o\o\[ \]
// All upper and lower-case letters will be escaped
// ... but so will the [\]^_` and any tabs, line
// feeds, carriage returns, etc.
style="color: #0000bb;">?><?php
echo addcslashes("zoo['.']", 'z..A');
// output: \zoo['\.']
?> What’s the difference between htmlentities() and htmlspecialchars()?
htmlentities — Convert all applicable characters to HTML entities
<?php
$str = "A 'quote' is <b>bold</b>";
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str);
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities style="color: #007700;">($str, ENT_QUOTES);
?><?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // <a href='test'>Test</a>
?> Generate Unique number in php and mysql
There are number of way to generate unique number or id in mysql and php.
Using Rand() function. we can get random data with in limit
SELECT * FROM company ORDER BY RAND() LIMIT 10<? echo str_replace ("}","",str_replace("{","",com_create_guid())); ?> <?$number = mt_rand(500 pan>,1000); ?><?$uniqid = date('U') . mt_rand(0,9); ?> <? echo time();?>
Get file extension using PHP
There are number of way to get file extension in php.
function getFileExtension($filename)
{
$fileinfo= pathinfo($filename);
return $fileinfo['extension'];
}
$ext = end(explode(‘.’, $file));
$ext = substr(strrchr($file, ‘.’), 1);
$ext = substr($file, strrpos($file, '.') + 1);
$ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $file);
$exts =split("[/\\.]", $file);
$n = count($exts)-1;
$ext = $exts[$n];
Show child Pages of a specific parent Page
you can use below code to show all child of
parent who has id 10.
<?php wp_list_cats('child_of=10'); ?>
you can also use this
<?php wp_list_pages('child_of=10&
sort_column=post_title&title_li=')?>
How to Show parent page title even on child page
<?php
if($post->post_parent) {
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
} else {
wp_title('');
}
?>
How to kill a MySQL query?
If you fired a query, that takes more time to complete their execution.
but you want to stop this query.
To stop this query you must use Kill command to achieve it.
Follow two step to kill your query.
mysql> SHOW PROCESSLIST;
above command will show all running process on the server.
Here you will see thread ID return by above command.
mysql> KILL 22;
kill thread 22 to kill your query.
WordPress Installation Guide.
To instilled wordpress on your site is very simple
If you are non technical person don’t worry, you can also install wordpress.
By follow 5 steps
1-Download wordpress and Unzip wordpress
2-Create a Database
3-Create a wp_config.php file from wp-config-sample.php
4-Upload wordpress filse on your server
5-Open wordpress folder via Browser
1-Download wordpress and Unzip wordpress
Download wordpress from http://wordpress.org/download/
And unzip the zip file via zip/unzip software or use default unzip program
After unzip you will be get wordpress folder like below
2-Create a Database for WordPress
In second step you need to create a database on your server.
To connect to database wordpress require some detail
Like
Database Name (Which you have created for word press)
Server Name (In which server data base has created)
User Name (User name to access data base)
Password (Password to access data base)
When you will create database from your server administration area and assign user then you will get above details.
If you are working on localhost.
Then simple create database from php phpmyadmin or other interface
Note:You don’t need to add any table in the database, wordpress will automatically add tables.
3-Create a wp_config.php file from wp-config-sample.php
This file contain database information .so we need to create a file name wp-config.php
To create a wp_config.php file, simple copy of all codes wp-config-sample.php and paste on other emplty file and save as wp_config.php or rename wp-config-sample.php to wp_config.php
Then you will see wp_config.php like below
Here you need to add valid details of database.
define(‘DB_NAME’, ‘putyourdbnamehere’);
/** MySQL database username */
define(‘DB_USER’, ‘usernamehere’);
/** MySQL database password */
define(‘DB_PASSWORD’, ‘yourpasswordhere’);
/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);
You need to change only above information.
If you are working on localhost , you need to replace define(‘DB_PASSWORD’, ‘yourpasswordhere’); to define(‘DB_PASSWORD’, ‘’);
And define(‘DB_USER’, ‘usernamehere’); to define(‘DB_USER’, ‘root’);
4-Upload wordpress filse on your server
In forth step you need to upload all wordpress file on your server
Via FTP or Control panel. its depend on you.
For FTP, You need to have any file uploader software. Like filezilla.
Download from here
http://filezilla-project.org/download.php
5-Open wordpress folder via Browser
After uploading all files on server. You need to open your site on browser.
If wordpress files are in root.
Then write URL http://www.domainname.com
Or if wordpress files are in a folder name, blog in the root, for this you need to write URL
http://www.domainname.com/blog/
after open URL, you will automatically see below window
Write your blog title and Your E-mail address and click on Install WordPress Button.
Please remember username/password .
Your blog username and password will also mail to your email address.
After click on login button you will see next screen
Congratulation, you have been successfully installed wordpress.
Now you can log in and start setting up your blog!
How many tables present in MySQL
Total 5 types of tables we can create
1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM
MyISAM is the default storage as of MySQL 3.23. When you fire the above create query MySQL will create a MyISAM table.
