Hello i have list of football teams on every line is a new team but there are countries in brackets i want to remove all of them, here is a example of the list:

Águila (El Salvador)
Águilas (Costa Rica)
Águilas Doradas (Colombia)
Árabe Unido (Panama)
Åtvidaberg (Sweden)
Ñublense (Chile)
Örebro (Sweden)
Örgryte (Sweden)
Öster (Sweden)
Újpest (Hungary)
Ústí nad Labem (Czech Republic)
Čelik Nikšić (Montenegro)
Čelik Zenica (Bosnia and Herzegovina)
České Budějovice (Czech Republic)
Čukarički (Serbia)
İnter Bakı (Azerbaijan)

Pls help me with this, so acually i need to take the first bracket on every line and delete the rest of it

Recommended Answers

All 5 Replies

If you just need to remove what comes after the first occurrence of the bracket and display what is remaining, then you could basically loop the input into strstr(), like this:

$line = 'Águila (El Salvador)';
$out = strstr($line, '(', TRUE) . '(';
print $out; # Águila (

See: http://php.net/manual/en/function.strstr.php
Example:

<?php

$fp = function($file) {

    $out   = '';
    $lines = file($file);

    foreach($lines as $line)
        $out .= strstr($line, '(', TRUE) . '(' . PHP_EOL;

    return $out;
};

$output = $fp('./input.txt');
print $output;

Or switch to fopen if the input is a big file.

You might want to use Notepad++ instead of Notepad. It's better, supports regular expressions, and is free. Your search term as a regex is

\(.*$

and your replacement text is blank. In brief "\(" matches a left parenthesis, ".*" matches any length string and "$" matches the end of line. In toto the string matches everything from the first "(" to the end of the line.

commented: +1 +14

Wait, was it about the editor?! O_O
I thought it was about PHP, sorry!

It was tagged notepad so I assume, editor.

Yes, I noticed that only after your answer. Usually Stefan writes about PHP, so I went in automatic. My bad.

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.