|
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
|
|||||||||
|
?>
|
||||||||||
|
||||||||||
|
Tuesday, 9 June 2020
how to convert line by line or array to string with seperator
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment