A
A
Alexey Tutubalin2015-01-12 15:53:06
PHP
Alexey Tutubalin, 2015-01-12 15:53:06

How to cut string in php?

There are lines with news titles (video films), the line obtained from the {title} tag consists of the
name of the film (one or several words), the year (not always) and the type of rip (it is not difficult to make a list (WEB-DLRip, WEBRip-AVC, etc.). etc.)) now I need to cut everything that is after a year, that is, a certain array with the detection of occurrences of the rip type, a
few 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 (2014)
Leviathan (2014)
The Equalizer (2014)

there were ideas to cut by a certain character, by the number of characters, but everything is not right, because in life you can’t guess what the name might be, there was only one idea to cut the line after the word from the list, but I can’t imagine how to implement this
PS it will all be on DLE

Answer the question

In order to leave comments, you need to log in

5 answer(s)
I
ivankomolin, 2015-01-12
@Kennius

preg_replace('/^(.*?)\s+(?:DVDScr|CAMRip|WEBRip|BDRip).*$/isu', '$1', $text);

Example:
$text = 'Великий уравнитель / The Equalizer (2014) BDRip от HQ-ViDEO | Лицензия';
var_dump(preg_replace('/^(.*?)\s+(?:DVDScr|CAMRip|WEBRip|BDRip).*$/isu', '$1', $text));die;

Output:
string(58) "Великий уравнитель / The Equalizer (2014)"

O
OnYourLips, 2015-01-12
@OnYourLips

Remove quality keywords (DVDScr, CAMRip, WEBRip-AVC)

A
Alexey Yakhnenko, 2015-01-12
@ayahnenko

/^(.+\(\d{4}\))/gi

V
Voenniy, 2015-01-12
@Voenniy

I did this (only the Russian name + year was needed) I pull out the
name to the special character (, / , etc.
I pull out the year separately. Then I output the already assembled one.
An example here is tracker.ru/search?q=%D0%B1%D0% BE%D0%B9 There
are a lot of movies that are grouped on the fly on the battle request.

R
Roman Olegovich, 2015-01-12
@RusPOPsy

so far only one idea comes to mind

$str = "Хоббит: Битва пяти воинств / The Hobbit: The Battle of the Five Armies (2014) DVDScr | CAMRip";
    $pm = array();
    preg_match('/\([0-9]{4}\)/', $str, $pm);
    $ps = preg_split('/\([0-9]{4}\)/', $str);
    $name = $ps[0].$pm[0];
    echo $name;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question