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

Friday, 28 March 2014

Explode function with file handling example

php explode implode function
The explode function with file handling example in php programming language. Will read the file. echo out to the user for reading the data of the file by file handling in php programming language.

Code for explode function with file handling example(Screenshot1)

explode function file handling php
Screenshot1

<?php



$filename = 'names.txt';

$handle = fopen($filename,'r');



$datain = fread($handle, filesize($filename));



$names_array = explode(',', $datain);



foreach($names_array as $name) {

echo $name. '<br>';

}



?>

Output (Screenshot2,)

php explode function
Screenshot2
In this example we are going to learn to read data from a file but obviously when u are reading data from the file. Its not always line by line basis. You may find commas separating your values and in this case we got few names here commas separated each value. Now how we deal with reading this in. Php file handling reading into the file. 

$handle fopen($filename, 'r');

Above code will create a handle to open and reading the file r stands for reading the file. We can also use file function which i had shown in example of file handling reading to the file. or we can also write  $handle fopen('names.txt','r');. I have taken names.txt in variale $filename for futhur use.

$datain = fread($handle, filesize($filename));

Above code will inilize the filesize will tell php file contain that much data instead of writing filesize we can also write the character we want from the file. like fread($handle,100); that's means it will contain 100 characters from the file.


$names_array = explode(',', $datain);

It will explode all commas from the file. Will remove commas from the file array of the name.

foreach($names_array as $name) {
echo $name. '<br>';
}

It will get array will write names one by one.
Read More

Friday, 28 February 2014

Basic Functions in php

Functions in php
Basic Functions in PHP Programming Languages. This tutorial is for Basic Functions. Why functions are useful in php and also in other programming languages? Lets see how we can create functions and use a function with our page. Firstly let me know you a function is something which allows you to declare a block of code that we may want to reuse,we use more arguments which is sometimes refractive.

Code for basic structure for functions(Screenshot1):-

Basic Functions In Php
Code for Basic Structure for Functions In Php Screenshot1

<?php



function MyName() {

echo 'Mohammed';

}



echo 'My name is <br>';

MyName();

?>

Output (Screenshot2):-

Basic function in php
Screenshot2
In this examples of basic structure of functions there is keyword “function” along with name of function i.e “MyName” and conditions in curly brackets. Since this example is basic so I am just showing you to echo out my name using functions. Then when we want to use functions we just had to call the function by name and conditions inside curly brackets are applied.
Now you need to think about it logically how you can use functions in your programs.
Read More

Thursday, 27 February 2014

For Loop in php


For Loop In Php Programming Languages. This tutorial is for “For Loop”. Now syntax of For Loop is bit complicated. Also,its structure is slightly different. If we make blogs related to For loop you must observe that its similar to While Loop and Do While Loop. However, in For Loop what we are doing is we use three expressions within this brackets.These three expressions are ,firstly to initialize the variable then control the loop by giving a definite condition to the variable and lastly increment the initialized value of variable.


Code for For loop (Screenshot1):-

For loop in php
Screenshot1

Output (Screenshot2):-

For Loop In Php
Screenshot2
In this example, I am firstly declaring variable “count” in For Loop,secondly evaluate whether condition is true or false i.e.count is greater than or equal to ten and lastly increment the value of count.In For Loop,”;” sign between these expressions is must.Second expression will only get executed after execution of first expression and third expression will only get executed after execution of second expression whenever any For Loop is called for the first time in program.But from second time onward it will only execute second and third expressions,since the initialization of variable is done while calling the For Loop for the first time.
Html tags should be in single inverted commas at echo function of php programming languages.

Code for For loop (Screenshot3):-

Loops
Screenshot3

Output (Screenshot4):-

for loop in php
Screenshot4
In this example, we are counting from 10 to 1 by decremented the value of variables.So, this is basic For Loop in php.
Read More

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates