Forum Moderators: coopster
Just see if this helps...
$comma = strpos($data_rows, ",");
if ($comma === true)
{
$data = explode(",", $data_rows);
}
else
{
//explode tabbed content
}
But what if it is tabbed but the string contains also a comma?
You might count the occurrences and see which one is really delimiting. But I don't see a way to surely tell what the delimiter is. For the following text, for example, you wouldn't know what the delimiter is just by looking at it.
this,text,is;second,part;and;third,part
I don't believe there is anything you can do, to surely tell what kind of delimiter a certain file contains.
name -
example_file.tab.php
example_file.comma.php
$dot = strpos($file_name, '.');
$type = substr($file_name, $dot+1, strlen($file_name)-4);
beginning of file -
type = tabbed ¦ comma
// rest of file contents start here
$find = preg_match('%^type =?(tabbed¦comma)%$', $file, $match);
$type = $match[1]; // this should be the parenthesised bit
At least those 2 versions may give you a better idea of how to find the type. Then you will know what delimiter you are looking for.