i new have tried learn as can before asking questions here. unfortunately, unlikely have vocabulary ask clear question. apologies , in advance.
is possible build array out of data several files? had series of text files , first line of each file 3 tags, separated commas, wanted stored in array of of tags of text files, how go that?
for example file might contain tags, title of page , content:
social movements, handout, international haiti , politics of resistance haiti, officially republic of haiti, caribbean country. occupies western, smaller portion of island of hispaniola, in greater antillean archipelago, shares dominican republic. ayiti (land of high mountains) indigenous taĆno or amerindian name island. country's highest point pic la selle, @ 2,680 metres (8,793 ft). total area of haiti 27,750 square kilometres (10,714 sq mi) , capital port-au-prince. haitian creole , french official languages. my desired outcome page containing of tags used in of text files can each clicked on see list of of pages containing tags.
never mind, now, want remove duplicate tags. need read first line of first file, explode line , write values array? , same next file? have attempted with, firstly:
$content = file('mytextfilename.txt'); //first line: $content[0]; echo $content[0]; that found here. followed stuff explode found here.
$content = explode(",",$content); print $content[0]; this did not work, obviously, in no position figure out why not. if have not explained myself please ask can attempt clarify question.
thank help, adam.
you can try:
$tags = array_reduce(glob(__dir__ . "/*.txt"), function ($a, $b) { $b = explode(",", (new splfileobject($b, "r"))->fgets()); return array_merge($a, $b); }, array()); // remove spaces $tags = array_map("trim", $tags); // make unique $tags = array_unique($tags); print_r($tags); since teething .. can consider version
$tags = array(); // define tags $files = glob(__dir__ . "/*.txt"); // load txt fules in current folder foreach($files $v) { $f = fopen($v, 'r'); // read file $line = fgets($f); // first line $parts = explode(",", $line); // explode tags $tags = array_merge($tags, $parts); // merge parts tags fclose($f); // closr file } // remove spaces $tags = array_map("trim", $tags); // make unique $tags = array_unique($tags); print_r($tags);
Comments
Post a Comment