Hello everone, i have a teams.txt file there are soccer clubs every team on new line i want to split the country from the club when is inserted into database. The country is the last string ex.
FC Barcelona (Spain)
Arsenal (England)
Any help will be appreciated.
I have tried with simple string variable and it works but i do not know how to from a file:

$string = "FC Vardar (Macedonia)";
$split = substr($string, 0, strrpos($string, " "));
echo $split;
Member Avatar for RudyM

Try this:

<?PHP
  $file_h = fopen("my_file.txt","r");

  while(!feof($file_h))
  {
    $line = fgets($file_h);

    $club = trim(substr($line, 0, strpos($line, "(")));

    $country = trim(substr($line, strpos($line, "(")+1));
    $country = str_replace(")","",$country);

    echo $club . " >> " . $country . PHP_EOL;
  }
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.