Tuesday, 9 June 2020

php explode

using explode functionin php
convert comma seperated string to array or line by line
vammsi, vamsi, vamsi, vamsi, vamsi - input is like this , how  can I print
convert line by line to comma or viceversa
explode
file
to save to variable from file, if input is in array then we take lik ethis
string format
fopen
<?php
$file = fopen('names.txt', 'r');
using open the names,text file and do the function which is instructed in right side
//echo fread ($file, 10);
upto 10 chcaracters only
$filesize= filesize($filename);
we don’t know to give number how much, if u give more, it is more wastage
$data = fread($file, $filesize);
read the text file which is on left side upto rightside
$namesar = explode(',' , $data);
using explode we can convert string to array

remove the seperators which is  on left side of righside file

explode automatically removes space, based on comma seeration, removes comma, converts into array
foreach ($namear as $name){
we already converted into array, but we need to print
echo $name. '<br>';
print one line and goto next line , print another line
}
?>
it wil print one white space
implode functuon

fopen
fread
filesize
fread(filename, size)
explode(seperator, file name)
foreach
how to open the text file to read the data
how to print the data in text file
how to get the size of the file or how many lines are there
how to read upto some size
how to convert string to array and remove seperators
how to print each and every line



No comments:

Post a Comment