Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Free resources ( websites ) to getting started with PHP ( Learn PHP )

PHP is having a huge scope in website development ( web applications development ). If you want to learn PHP then we are helping you with the free resources.

Free resources ( websites ) to getting started with PHP ( Learn PHP ):

  • Learn PHP with w3schools - https://www.w3schools.com/php/default.asp
  • TutorialsPoint - Learn PHP Free - https://www.tutorialspoint.com/php/index.htm
  • Learn PHP free with PHP The Right Way - https://phptherightway.com/
  • PHP Tutorials on GeeksForGeeks - https://www.geeksforgeeks.org/php/
  • PHP tutorials on SitePoint -  https://www.sitepoint.com/php/
  • Hacking with PHP - http://www.hackingwithphp.com/
  • Getting started with official PHP Manual - https://www.php.net/manual/en/getting-started.php

How can we echo the variable multiple times in PHP?

 The very simple PHP interview question always get asked to PHP Fresher in a job interview.



And the question you already see in a title is: How can we echo the variable multiple times in PHP?

Answer:

You can do it by multiple ways.

Example:

<?php

$my_variable = "echo me 7 times";

//how to echo the $my_variable 7 times

?>


Option 1:

echo it 7 times manually/individually as

<?php

$my_variable = "echo me 7 times";

echo $my_variable . "<br/>";

?>


Option 2:

Use for loop as:

<?php

$my_variable = "echo me 7 times";

for($i=0;$i<7;$i++){

  echo $my_variable . "<br/>";

}

?>


Option 3:

Use str_repeat() string function as:

<?php

$my_variable = "echo me 7 times";

echo str_repeat($my_variable , 7);

echo "<br/>";

?>

In this way you can print the variable multiple times in PHP. 

Now you can try above solutions on your machine or run PHP examples online.


Interview Question: Difference between Ruby and PHP


Interview Question with Answer
What are the difference between Ruby and PHP?


Difference between Ruby and PHP


Both Ruby and PHP languages are widely used. The websites of such well-known companies as Twitter, Hulu and Groupon are developed on Ruby. PHP is a language of Udemy, Wikipedia, and Facebook.
Difference between Ruby and PHP
Difference between Ruby and PHP


1. Ruby syntax is easy-to-comprehend, while PHP code may cause problems because of its syntax nature and standard library.

2. Statement terminator.
In Ruby, it is a newline character, in PHP – semicolon. For PHP, there is no secondary statement separator, while for Ruby it is a semicolon.

3. In PHP, blocks of code are ended with curly brackets, in Ruby – with the word ‘end’.

4. Integer data types. Ruby – no support, PHP supports 32-bit and 64-bit ones.

5. Frameworks.
Ruby – Cramping, Cramp, Ruby on Rails, Grape, Fiasco, Cuba. PHP – CakePHP, Codelgniter, Symfony, etc.


Most Important PHP Interview Questions and Answers

Most Important PHP Interview Questions and Answers




PHP Interview Questions and Answers
Question: 
What’s the difference between the include() and require() ?
Answer:
The Purpose of both is include() and require() is "to include a specific file"
The require() function is identical to include(), except that it handles errors differently. If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop.

Question: 
How can we get the IP address of the client?
Answer:
$_SERVER["REMOTE_ADDR"]; gives the IP address from which the request was sent to the web server

Question:
 Is multiple inheritance supported in PHP ?
Answer:
 NO, multiple inheritance is not supported by PHP

Question: 
What is the difference between unset and unlink ?
Answer:
 unlink is used to remove/delete files.
 unset is used to unset a variable

PHP: Power of PHP

Some of the important points regarding PHP:
  • PHP can create, open, read, write, delete, and close files on the server
  • PHP can collect form data
  • PHP can send and receive cookies
  • PHP can add, delete, modify data in your database
  • PHP can be used to control user-access
  • PHP can encrypt data
  • PHP can generate dynamic page content
  • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  • PHP supports a wide range of databases
  • PHP is easy to learn and runs efficiently on the server side



Jobs After MCA - Job Opportunities after MCA - MCA jobs

Jobs After MCA - Job Opportunities after MCA - MCA jobs




Many IT students asking us to write more about MCA jobs. We are getting questions like:

What should I do after MCA?
What are the MCA Jobs after MCA?
Which job should I choose after MCA?
What is the scope of MCA?

So, we at Technology Park decided to write more about MCA jobs.

We at Technology Park Blog, helping IT Students, IT Freshers to get a right job. We are also trying to help to build good resume, for that we are providing resume tips for IT Students and IT Freshers.

What is MCA?

MCA stands for Master in computer Application. MCA is 3 years Post Graduate degree. After Completion of MCA you dont need to take any degree further. If you passed out with MCA then its right time to get a right job.

MCA course includes various theoretical and practical subjects like:
C, C++, Java, ASP.NET, PHP, Algorithms, Data Structure, Database Management System ( DBMS ).
Read this Post:
MCA course - Scope of MCA and Job Opportunities for MCA students

Careers after MCA / MCA Jobs / Job Opportunities after MCA :

Many Many jobs are available for MCA candidates. Most important thing is your skill. First decide that in which technology you are interested to do a job.

If you love to design a forms, if you have good knowledge about CSS, HTML, Photoshop then you choose Website Design. There are many jobs for Website Designers. Build your resume mentioning your Web Design Skills.
If you are strictly want to go for Website Design field then remove other skills from your resume, or remove other skills which you have updated on Job Portals.
If you have only website design skills in your resume and Job Profile on Job Portals then you will get interview calls from Companies for Website Design Jobs.
So, Website Designer is job which will give you satisfaction of work because you love the website design. Website Design is best job in category of MCA jobs.

PHP Developer Jobs:



If you have basic knowledge of PHP and MySQL then you can easily grab the PHP Developer Job.  After MCA you can do a PHP Developer Job.
PHP is very easy to learn. PHP is open source.
If you want to do a job in PHP then you must have a practical knowledge of PHP and MySQL.

Basic Preparation for PHP Interview includes:
PHP variables,
PHP arrays,
PHP array functions,
PHP forms, form attributes,
PHP GET and POST methods,
PHP sessions and cookies,
PHP error Types,
PHP File Upload,
PHP String Functions,
Send email using PHP

MySQL database Operations - insert, update, delete, SQL joins, Nested Query, Primary key, Unique key, Constraints ( Not NULL, NULL), etc

If you want to become a PHP developer then you must read following post:
How to Prepare for interview of PHP developer?

We will write more about MCA Jobs in next article.

Here are various Job Opportunities after MCA:

  • Software Developer
  • Software Engineer or Programmer
  • Website Developer
  • Website Designer
  • DBA
  • Softare consultant
  • Network Engineer
  • System Engineer
  • Implementation Engineer
  • Software Tester
  • Hardware Engineer
  • Mobile Application Developer
  • Technical Analyst
  • Project Manager
  • Technical Recruiters
  • Technical Support

You can search MCA Jobs here: MCA Jobs

Best Luck!



If you have any questions or doubts about MCA jobs then please write in Comments.

MCA course - Scope of MCA and Job Opportunities for MCA students

Many students approached us to write about the MCA course scope and career opportunities for MCA students.

What is MCA?

MCA is Post graduation course which includes software/website development subjects. MCA course includes both theoretical and practical knowledge about almost all the programming languages like, c, c++, ASP, ASP.NET, PHP, etc and the Database knowledge like RDBMS, MySQL, MS-Access, Oracle. Management and soft skills development subjects also part of the MCA course.

MCA course prepares the candidate to enter into the IT industry.

Syllabus of MCA Course can be different according to universities.

To get the admission for the MCA course main eligibility is "graduate". And the mandatory thing is MCA CET. If the candidate wants to take admission for MCA then he must be graduated and better score in MCA CET.

Job Opportunities for MCA Student:

If you passed out with good score in MCA course then you need to find out the right job which suits for you.

If you love to design a web then you should start to find a job in website design. To enter into a website design you must have the knowledge of HTML, CSS, Photoshop, Javascript, etc.

If you love to work upon database operations like writing optimized queries, SQL procedures, Triggers, Joins then you may interested in joining DBA position in IT company.

Likewise various job opportunities are available in market for skilled candidate.

To get a job first and most important thing is "your skill".

If you are good at PHP server side Programming Language then you may go for PHP developer position. There are various job opportunities for PHP developers in IT industry. Most of the companies are using PHP for their projects.

To get a job as a PHP Developer you must read this post >>

How to Prepare for interview of PHP developer?



Software testing is also best career opportunities after MCA.
Animation is most valued career to enter into after MCA.

Many many jobs are available after MCA, just important thing is your interest and skills.

We at Technology Park posts Job opportunities here on this blog, so please visit this blog daily for Job Openings.



Best Luck.

If you have anything to share with us then please share your thoughts in comments. Thanks!

How to Prepare for interview of PHP developer?

As we have received many requests for writing article for How to Prepare for interview of PHP developer?

We can not give complete guidance in one article here but we will try to give enough information regarding How to Prepare for interview of PHP developer.




To become PHP developer means to get a job as a PHP developer or PHP programmer or Web Developer you must have at least bachelor degree. Many companies prefer the Qualification criteria as:
BCA, BSC-IT, BSC-Computers, MCA, MCM, BE-IT.

If you are not having any of the above degree but you are having enough practical knowledge of PHP then some of the small companies can hire you as a PHP Developer.

Coming to the preparation for the PHP Developer Job  ( How to get a job as PHP Developer )
 First and most important part is Build your Resume properly. Resume is the entry point for you. If your Resume is not good then you may loss the opportunity to enter into IT industry.

So, what means Good Resume?
Here we provide Best Resume Tips for Freshers.
Please go through the following links to build a best Resume:
Resume Tips For Freshers - 1

Resume Tips For Freshers - 2

Next, Prepare for PHP Interview Questions.
You must have basic knowledge of all the basic concepts of PHP.




Here I am providing some of them:

What is WAMP / XAMPP?

PHP Variables - 1
PHP Variables - 2

GET method and POST method in PHP

How to Include File in PHP

Arrays in PHP

Types of array in PHP

Array functions in PHP

For Loop in PHP with Example

Errors in PHP, Types of Errors in PHP

String Functions in PHP

Form attributes

How to upload file in PHP?

File Operations in PHP?

Session and Cookies in PHP

Difference between unlink and unset in PHP

How to send mail using PHP?

explode function in php

MySQL functions to create connection, insert , update, delete.

Database connection using PHP MySqli


Basic Concepts of Javascript

Basic PHP programs in PHP:
PHP program to check whether the given number is palindrome or not
PHP program to check whether the given number is prime or not

Here we are providing all PHP Interview Questions with Answers
PHP Interview Questions with Answers
All PHP Interview Questions with Answers
Important PHP Interview Questions with Answers

Here we are providing some important HR interview questions with Answers:
Tell me about Yourself
How long would you stay with us? HR Interview Question


In this way we have tried our best to give you a guidance regarding How to Preppare for interview of PHP developer.

We will be writing most important content on this blog for BCA Freshers and MCA freshers regarding Resume Tips, Interview Questions, Technical Concepts explanation with very easy language.




Share this Post with your Friends.
Help people, people will help you!

Related Post - Top PHP frameworks used for Web Development

Variables Scope in PHP : Explained in easy language

Variables Scope in PHP

There are three types of variable scopes in PHP .  They are as follows:

1)      Local

2)      Global

3)      Static

Local Scope : When a variable declared inside a function (has a local scope ) and it can only be accessed within that function, the variable is called as local scope variable .

E.g.

<?php

function localvar()

{

$x=6; //local scope variable

echo "Variable x inside function is : $x";

}

localvar();

echo "Variable x outside function is : $x";//generate an error like undefined variable

?>

 

Output:  

Variable x inside function is : 6

Notice: Undefined variable: x

Variable x inside function is :

 

Global Scope : When a variable declared outside a function (has a global scope) and it can only be accessed outside a function, the variable is called as global scope variable .

E.g.

 <?php

$x=10; //global scope

function globalvar()

{

echo "Variable x inside function is : $x";//generate an error like undefined variable

}

globalvar();

echo "Variable x outside function is : $x";

?>

Output:

Notice: Undefined variable x

Variable x inside function is :

Variable x outside function is : 10

Global Keyword : By using global keyword we can access a global variable within a function. Just add or write global keyword before the variables inside the function. As follows,

e.g.

<?php

$x=10; //global scope

function globalvar()

{

            global $x;//By using global keyword

echo "Variable x inside function is : $x<br>";

}

globalvar();

echo "Variable x outside function is : $x";

?>

Output :

Variable x inside function is : 10

Variable x outside function is : 10

 

Static Scope : When a function is executed , all of its variables are deleted. However we want a local variable not to be deleted. We need it for further job. Use the static keyword when you first declared the variable . Then each time the function is called , the variable will still have the information it contained from the last time the function called.

e.g.

<?php

function scopevar (){

            static $x=11;

            echo $x;

            $x++;

}

scopevar ();

echo "<br>";

scopevar();

echo "<br>";

scopevar ();

?>

Output :

11

12

13

     

              In that way we learn variables scope in short .

Note: Read this blog regularly for important concepts and interview questions.

This blog is useful for IT students, IT freshers, BCA/MCA freshers. This blog contains Resume Tips, interview questions with answers.

PHP Interview questions with answers for Freshers - 1

Many interview questions we already listed on this blog, please read through out the posts related to PHP interview questions.


Q. What is the use of "echo" in php?
Answer: It is used to print a data in the webpage,
Example: <?php echo 'Welcome to Technology Park'; ?>
It will print the output or text on webpage as:
Welcome to Technology Park

Q. How to include a file to a php page?
VERY IMPORTANT INTERVIEW QUESTION
Answer: We can include a file using "include() " or "require()" function with file path as its parameter.

Q. How stop the execution of a php scrip ?
Answer: exit() function is used to stop the execution of a page.
At any point of script you can use the exit or exit() statement.

example:
<?php
echo "Welcome to Technology Park";
exit();
echo "not printed";
?>

Output:
Welcome to Technology Park

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


Keep visiting the blog regularly for Latest Interview questions and Resume Tips.

PHP program to check whether the given number is palindrome or not

This PHP program is very useful for IT freshers.

Most of the IT companies ask this program in technical interview.




PHP program to check whether the given number is palindrome or not.

<?php
// PHP program to check whether the given number is palindrome or not
$n=123;
$rev=0;
$n1=$n;
while((int)$n > 0){
$rem = $n % 10;
$rev = ($rev*10) + $rem;
$n = (int)$n / 10;
}
echo "Reverse of $n1 = ".$rev."<br/>";
if($n1 == $rev){
echo "$n1 is palindrom number";
}else{
echo "$n1 is not palindrom number";
}
?>

This blog is very useful for IT Freshers.
Use right side menus to read useful posts like Resume Tips, Interview questions, Jobs, Programming, etc.

Other important Posts:
How to find PHP version through command prompt in windows? 

Important PHP string functions


PHP program to check whether the given number is prime or not

This post is very important for IT Students and IT freshers.

The most important program asked in various interviews or technical tests:
Write a PHP program to check whether the given number is prime or not.




What is Prime number: the number which is divisible by 1 and itself only.


So, here is the Program to check whether the given number is prime or not.

<?php
// What is Prime number: the number which is divisible by 1 and itself only.
$n=6; // The number which we want to check if it is PRIME or NOT PRIME
$prime=true;
for($i=2;$i<$n;$i++){
if($n%$i == 0){
$prime = false; // If Number is divisible by the $i iteration, it is not prime
break;
}
}
if($prime){
echo "PRIME";
}else{
echo "NOT PRIME";
}

?>

Output:
NOT PRIME

// when we assign value to n is 5 then output will be PRIME
--------------------------------------------------------------------------------------------




Other important posts for students of BCA/MCA/MCM/Msc/Bsc/MBA-IT/BE/BTech

Guidance for IT Students

Future of PHP Developer

PHP: Past, Today and Future

This blog is very helpful for IT Students and IT Freshers.


Database connection using PHP MySqli

For PHP freshers, one important thing is mysql_* functions are deprecated. Instead of mysql_* functions now we use mysqli_* functions.

PHP mysqli_connect() Function is used for connection to mysql database.




Example
Open a new connection to the MySQL server:

<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>


If we are using wamp or xamp on localhost,
my_user = root

my_password = "" (blank/empty)
my_db = your database name


This function returns an object representing the connection to the MySQL server, the returned connection object is used for executing mysql queries.


Insert Data Into MySQL Using MySQLi:
The INSERT INTO statement is used to add new records to a MySQL table:

INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

Example:
The following examples add a new record to the "MyGuests" table:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";

if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>


In this way, we just understood the concept and basics of mysqli connection.



Multidimensional Arrays in PHP: syntax and example

Multidimensional Arrays in PHP:
In previous post Arrays in PHP we learned Arrays and types of arrays.
We understood the concept of regular array that is indexed array, it is also called numeric array. We understood associative array.

Now we are going to understand Multidimensional array.
A multidimensional array is an array containing one or more arrays. It is also called array of array.

A multi-dimensional array each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. Values in the multi-dimensional array are accessed using multiple index.

Two-dimensional Arrays:
A two-dimensional array is an array of arrays (a three-dimensional array is an array of arrays of arrays).




example:
<?php
$students=array(
          array('Vanesh', 'MCA', '78'),
          array('Ganesh', 'MCM', '83'),
          array('Ramesh', 'MSC', '64'),
);

echo $students[0][0]." ".$students[0][1]." ".$students[0][2]. "<br/>";
echo $students[1][0]." ".$students[1][1]." ".$students[1][2]. "<br/>";
echo $students[2][0]." ".$students[2][1]." ".$students[2][2]. "<br/>";

?>


output:
Vanesh MCA 78
Ganesh MCM 83
Ramesh MSC 64

We can print this array using foreach loop as:

<?php
$students=array(
          array('Vanesh', 'MCA', '78'),
          array('Ganesh', 'MCM', '83'),
          array('Ramesh', 'MSC', '64'),
);
foreach($students as $key => $val){
  foreach($val as $v){
      echo $v." ";
    }
  echo "<br/>";
}
?>

output:
Vanesh MCA 78
Ganesh MCM 83
Ramesh MSC 64

Arrays in PHP

Arrays in PHP:
An array stores multiple values in one single variable.




An array is a data structure that stores one or more similar type of values in a single value.

Types of array:

There are three different kind of arrays and each array value is accessed using an ID c which is called array index.

Numeric array − An array with a numeric index. Values are stored and accessed in linear fashion.

Associative array − An array with strings as index. This stores element values in association with key values rather than in a strict linear index order.

Multidimensional array − An array containing one or more arrays and values are accessed using multiple indices.

Numeric Array
These arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero.

Example
Following is the example showing how to create and access numeric arrays.

Here we have used array() function to create array. In PHP, the array() function is used to create an array.

<?php
         /* First method to create array. */
         $numbers = array( 1, 2, 3, 4, 5);
         
         foreach( $numbers as $value ) {
            echo "Value is $value <br />";
         }
         
         /* Second method to create array. */
         $numbers[0] = "one";
         $numbers[1] = "two";
         $numbers[2] = "three";
         $numbers[3] = "four";
         $numbers[4] = "five";
         
         foreach( $numbers as $value ) {
            echo "Value is $value <br />";
         }
      ?>

Output:
Value is 1 
Value is 2 
Value is 3 
Value is 4 
Value is 5 
Value is one 
Value is two 
Value is three 
Value is four 
Value is five 

Associative Arrays:
Associative arrays are arrays that use named keys that you assign to them.

There are two ways to create an associative array:

$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

or:

$age['Peter'] = "35";
$age['Ben'] = "37";
$age['Joe'] = "43";
The named keys can then be used in a script:

Example
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
?>

OUTPUT:
Peter is 35 years old.

Loop Through an Associative Array
To loop through and print all the values of an associative array, you could use a foreach loop, like this:

Example
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

foreach($age as $x => $x_value) {
    echo "Key=" . $x . ", Value=" . $x_value;
    echo "<br>";
}
?>

OUTPUT:
Key=Peter, Value=35
Key=Ben, Value=37
Key=Joe, Value=43




Multidimensional Arrays:

Multidimensional Arrays will learn in next lession. 

For loop in PHP : Introduction with Example

The PHP for Loop:



The for loop is used when you know how many times you want to execute a statement or a block of statements.

Today we are going to learn for loop in php.

Syntax:

for (init counter; test counter; increment counter) {
    code to be executed;
}

Parameters:

init counter: Initialize the loop counter value
test counter: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends.
increment counter: Increases the loop counter value

The example below displays the numbers from 0 to 10:

Example
<?php 
for ($x = 0; $x <= 10; $x++) {
    echo "The number is: $x <br>";
} 
?>

OUTPUT:
The number is: 0
The number is: 1
The number is: 2
The number is: 3
The number is: 4
The number is: 5
The number is: 6
The number is: 7
The number is: 8
The number is: 9
The number is: 10




Important PHP string functions

PHP string functions:
In this post we will look at some commonly used functions to manipulate strings.

Note: It is important for Interview questions.




strlen() function in PHP:
The PHP strlen() function returns the length of a string.
The example below returns the length of the string "Welcome to PHP":

Example

<?php

echo strlen("Welcome to PHP"); // OUTPUT: 14

?>

In above example "Welcome to PHP" this parameter passed to strlen() function and we used echo statement so it prints 14 as a output.
Welcome=7
to=2
PHP=3
2 sapces.

strtoupper() function in PHP:
The strtoupper() function converts a string to uppercase.
Example
Convert all characters to uppercase:

<?php

echo strtoupper("Hello WORLD!"); 
// OUTPUT: HELLO WORLD!

?>

strtolower() function in PHP:
The strtolower() function converts a string to lowercase.
Example
Convert all characters to lowercase:

<?php

echo strtolower("Hello WORLD."); // OUTPUT: hello world.

?>

ucfirst() function in PHP:
The ucfirst() function converts the first character of a string to uppercase.
Example
Convert the first character of "hello" to uppercase:

<?php

echo ucfirst("hello world!"); // OUTPUT: Hello world!

?>


ucwords() function in PHP:
The ucwords() function converts the first character of each word in a string to uppercase.
Example
Convert the first character of each word to uppercase:

<?php

echo ucwords("hello world"); // OUTPUT: Hello World!

?>

strrev() function in PHP:
The PHP strrev() function reverses a string:
Example:

<?php

echo strrev("Vanesh"); // OUTPUT: hsenaV

?>

strpos() function in PHP:
The PHP strpos() function searches for a specific text within a string.
If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE.

The example below searches for the text "world" in the string "Hello world!":

Example
<?php

echo strpos("Hello world!", "world"); // OUTPUT: 6

?>

str_replace() function  in PHP:
 - Replace Text Within a String
The PHP str_replace() function replaces some characters with some other characters in a string.

The example below replaces the text "world" with "Dolly":

Example
<?php

echo str_replace("world", "Vanesh", "Hello world!"); 
// OUTPUT: Hello Vanesh!

?>

strstr() Function in PHP:

Example
Find the first occurrence of "world" inside "Hello world!" and return the rest of the string:

<?php

echo strstr("Hello world!","world");

?>

OUTPUT: world!
The strstr() function searches for the first occurrence of a string inside another string.
This function is case-sensitive. For a case-insensitive search, use stristr() function.
Important: It returns the rest of the string (from the matching point), or FALSE, if the string to search for is not found.

str_repeat() function in PHP:
Repeats a string a specified number of times.

Example
Repeat the string "v" 10 times:

<?php

echo str_repeat("v",10); 
// OUTPUT: vvvvvvvvvv

?>

substr() function in PHP:
The substr() function returns a part of a string.

Example
Return "world" from the string:

<?php

echo substr("Hello world",6); 
// OUTPUT: world

?>

Above php string functions are very important, and important for Interview Questions.


How to print in php: echo and print in php

Today we are going to learn how to print in PHP.




echo in PHP:
The echo() function outputs one or more strings. Return Value: No value is returned.

example:

<?php
echo "Hello world!";
?>


Output:
Hello world!

other example:
<?php
$foo = "foobar";
$bar = "barbaz";
echo "foo is $foo"; // foo is foobar
?>


other example: Join two string variables together
<?php
$str1="Hello world!";
$str2="What a nice day!";
echo $str1 . " " . $str2;
?> 


output:
Hello world! What a nice day!

Tip: The echo() function is slightly faster than print().


print() in PHP:
The print() function outputs one or more strings. It always returns 1.

example:

<?php
print "Hello world!";
?>


Output:
Hello world!

Tip: The print() function is slightly slower than echo().



Learn PHP: read and understand these posts:

Learn PHP : PHP variables
How to find PHP version through command prompt in windows?
Learn PHP: Hour 1
Learn PHP: Hour 2

Important PHP interview questions for freshers











MOST IMPORTANT INTERVIEW QUESTIONS PHP

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

QUESTION. What is difference between “include” and “require” in php?
Answer. The include and require statements are identical, except upon failure:

require will produce a fatal error (E_COMPILE_ERROR) and stop the script
include will only produce a warning (E_WARNING) and the script will continue

QUESTION:  What are the different errors in PHP?
Answer. There are 4 basically types of error.
Parse Error – Commonly caused due to syntax mistakes in codes e.g. missing semicolon, mismatch brackets.
Fatal Error – These are basically run time errors which are caused when you try to access what can’t be done. E.g. accessing a dead object, or trying to use a function that hasn’t been declared.
Warning Error – These occurs when u try to include a file that is not present, or delete a file that is not on the server. This will not halt the script; it will give the notice and continue with the next line of the script.
Notice Error – These errors occurs when u try to use a variable that hasn’t been declared, this will not halt the script, It will give the notice and continue with the next line of the script.

QUESTION: What is session and why do we use it?
Answer. Session is a super global variable that preserve data across subsequent pages. Session uniquely defines each user with a session ID, so it helps making customized web application where user tracking is needed.

QUESTION: What is cookie and why do we use it?
Answer. Cookie is a small piece of information stored in client browser. It is a technique used to identify a user using the information stored in their browser (if already visited that website) . Using PHP we can both set and get COOKIE.

To read all PHP interview questions click here.









Learn PHP : PHP variables

Considering you know the installation and configuration of WAMP or XAMPP, and you have setup your PHP on your local machine.

This is guidance for candidates who really want to learn PHP.

So, Start.
Before you continue you should have a basic understanding of the following:
  • HTML
  • CSS
  • JavaScript




We are starting with variable.

What is PHP variable?
Answer: Variables are "containers" for storing information.

In PHP, a variable starts with the $ sign, followed by the name of the variable:

Example

<?php
$txt = "Hello world!";
$x = 10;
$y = 20;
?>
In above example, $txt is variable, which stores value "Hello word!". 
$x and $y also variables and they stores value as 10 and 20 respectively.

Note that when you are going to store string or text in variable do include that string in single quote or double.

If you want to store integer value in variable don't use quotes.

Using that variables as for example:

<?php
 echo $txt; 
echo "<br/>";
echo $x;
echo "<br/>";
echo $y;
echo "<br/>";

$z=$x$y;
echo $z;

 ?>

Output:
Hello word!
10
20
30

Explaination:
echo is construct we use to print in PHP. There is <br/> tag used with this echo that is for print new line.
$z stores sum of $x and $y.

In PHP we don't specify data type of variable, it automatically recognize.

That's it for this post, will post something important in next post, stay connected.