Пример #1
0
<?php 
$local = fread(utf8_fopen_read("Local.txt"), 100000000);
textToArray($local);
function textToArray($text)
{
    $personsArray = [];
    $textArray = [];
    $textArray = explode("\n", $text);
    //print_r($textArray);
    $i = 0;
    foreach ($textArray as $textElement) {
        $textPart[$i] = explode(">", $textElement, 2);
        $textPart[$i][0] = substr($textPart[$i][0], 50, -1);
        if (array_key_exists($textPart[$i][0], $personsArray)) {
        } else {
            $personsArray[$textPart[$i][0]] = [];
        }
        if (array_key_exists($textPart[$i][1], $personsArray[$textPart[$i][0]])) {
            $personsArray[$textPart[$i][0]][$textPart[$i][1]]++;
        } else {
            $personsArray[$textPart[$i][0]][$textPart[$i][1]] = 1;
        }
        $i = $i + 1;
    }
    foreach ($personsArray as $person) {
        $diffText = count($person);
        $textAmount = 0;
        foreach ($person as $text) {
            $textAmount = $textAmount + $text;
        }
        if ($diffText / $textAmount * 100 < 10) {
Пример #2
0
<?php

header('Content-Type: text/csv;charset=UTF-8');
header('Content-Disposition: attachment; filename=data.csv');
$uploadOk = 1;
$fileType = pathinfo(basename($_FILES["sourceFile"]["name"]), PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if ($fileType == "txt") {
    $handle = utf8_fopen_read($_FILES["sourceFile"]["tmp_name"], "r");
    if ($handle) {
        echo "";
        // UTF-8 BOM
        while (($line = fgets($handle)) !== false) {
            $line = str_replace("\r", "", $line);
            $line = str_replace("\n", "", $line);
            $line = preg_replace('!\\t+!', '","', $line);
            $line = str_replace('",""', '","', $line);
            $line = str_replace('"","', '","', $line);
            if (substr($line, 0, 1) != '"') {
                $line = '"' . $line;
            }
            if (substr($line, -1, 1) != '"') {
                $line = $line . '"';
            }
            echo $line . "\r\n";
        }
        fclose($handle);
    } else {
        echo "Error opening file";
    }
} else {