A
A
Alexey Tutubalin2015-12-10 15:30:29
PHP
Alexey Tutubalin, 2015-12-10 15:30:29

How to cut a string in php?

There are lines with movie titles,
some examples as is


The Hobbit: The Battle of the Five Armies (2014) DVDScr | CAMRip
Leviathan (2014) WEBRip-AVC
The Equalizer (2014) BDRip by HQ-ViDEO | License

how to

The Hobbit: The Battle of the Five Armies
Leviathan the
Great Equalizer

that is, cut everything from the right to the first from the left "(" and "/"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jelezo, 2015-12-10
@Kennius

Well, for your specific case:

$row="Слуга народа (1 сезон: 1-24 серия из 24) (2015)";

if(!($str=strpos($row, "/"))) $str=strpos($row, "(");
echo $row=substr($row, 0, $str);

B
bears, 2015-12-10
@bears

As an option:

$array = [
    'Слуга народа (1 сезон: 1-24 серия из 24) (2015)',
    'Хоббит: Битва пяти воинств / The Hobbit: The Battle of the Five Armies (2014) DVDScr | CAMRip',
    'Левиафан (2014) WEBRip-AVC'
];

echo "<pre>";

$delimeters = ['/', '('];

foreach ($array as $str) {
    foreach ($delimeters as $delimeter) {
        if ($position = strpos($str, $delimeter)) {
            echo substr($str, 0, $position) . "\n";
            break;
        }
    }
}

D
Dmitry, 2015-12-10
@mytmid

Maybe so?
$str - input data, where each line is processed separately.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question