Add initial implementation of Fantacalcio application

This commit is contained in:
Simone
2026-03-07 17:15:34 +01:00
parent 6e74a538ea
commit dc6fc7b7e0
41 changed files with 2086 additions and 0 deletions
Executable
+53
View File
@@ -0,0 +1,53 @@
<?php
/**
* Detects the field delimiter (';' or ',') for a CSV file.
* It bases the detection on the character count in the header row.
*/
function detectSeparators(string $csvContent): array
{
$lines = preg_split('/\r\n|\n|\r/', trim($csvContent));
$header = $lines[0] ?? '';
$semicolonCount = substr_count($header, ';');
$commaCount = substr_count($header, ',');
// If comma count is higher, we assume comma is the delimiter.
// Otherwise, we default to semicolon, which is common in many European locales.
if ($commaCount > $semicolonCount) {
$delimiter = ',';
} else {
$delimiter = ';';
}
// The decimal separator is no longer detected here,
// as it will be handled on a per-value basis.
return [
'delimiter' => $delimiter
];
}
/**
* Recursively traverses an array and converts numeric strings to int or float.
* Non-numeric strings are left unchanged.
*
* @param array $array The array to process, passed by reference.
*/
function recursively_convert_numeric_strings(array &$array)
{
foreach ($array as &$value) {
if (is_array($value)) {
// If the value is an array, recurse into it
recursively_convert_numeric_strings($value);
} elseif (is_string($value) && is_numeric($value)) {
// If the value is a string and represents a number, convert it
// Check if it's an integer or a float
if ((float)$value == (int)$value) {
$value = (int)$value;
} else {
$value = (float)$value;
}
}
// If it's not a string, not numeric, or not an array, it's left as is.
}
}