Tuesday, 9 June 2020

how to convert line by line or array to string with seperator

how to convert line by line or array to string with seperator
array to string
<?php
$names = array ('rafiquee', 'sameer', 'azamm');
echo implode(', ', $names);
rafiquee, sameer, azamm
?>
file line by line to string
<php
$file = file('names.txt' );
presently the data is in line by line
$file_string = implode(',',  $file);
vamsi
echo $file_strting;
rafiquee ,vamsi ,krishna
?>
we not given space, white s[pace is created
<?php
load the data like a array, before load remove space
$file = file('names.txt');
in namestext file data is in line by line
$c = 0;
assign 0 to c
foreach($file as $name){
using for each  go to each and every line of file
$names_array[$c] = trim($name);
trim the name without space and assign to names array in line by line
$c++;
}

convert line by line to string with seperatros
$names_string =  implode(',', $names_array);
vamsi, krishna, simha
echo $names_string;
right side is fiule and left side is seperator
?>
array
implode
file
implode
file
foreach
trim
c++
implode
how to create a array and how to conver that to string
how to print that string
how to read the file which has data is in line by line
how to convert line by line data to string 
how to print the data in file
how to over come,It prints some unnecessaary space
how to select the file
how to print the array file convert to string without unnecessary spaces

No comments:

Post a Comment