Extract characters from string in php

Suppose the line is Motive S01E13 HDTV x264 EVOLVE eztv I need to find out which episode is on this line. This is obviously episode 1 of season 13. I need to extract 13 from the line. I am new to PHP. So let's say:

$title = 'Motive S01E13 HDTV x264 EVOLVE eztv'; 

I need to find "E" and see if the next two characters are numeric. I guess ... Thanks in advance!

+4
source share
2 answers

I think this is what you are looking for:

 $title = 'Motive S01E13 HDTV x264 EVOLVE eztv'; preg_match('/s\d\de(\d\d)/i', $title, $matches); echo $matches[1]; // 13 

This will print 13 as you search. It will work with any similar formatted string and will always output the episode number (subject to the S00E00 format). It is also case insensitive if you're interested.

+2
source

You can try this

 $title = 'Empire S01E13 HDTV x264 EVOLVE eztv'; preg_match('/e(\d{2})/i', $title, $matches); echo $matches[1]; // 13 

Demo.

+1
source

Source: https://habr.com/ru/post/1496086/


All Articles