Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove All Text After Certain Point

Tags:

string

php

Hey, I'm just wondering how I could remove all the text if it encounters a certain string inside a string :

EX: 24 Season 1 Episode 3

I would like, that if it find the text Season that it removes it and everything after so it would just leave you with :

24

Thanks

Ah sorry I forgot to say I need this in PHP.

like image 801
Belgin Fish Avatar asked Dec 29 '22 03:12

Belgin Fish


2 Answers

With PHP5.3. you can use

echo strstr('24 Season 1 Episode 3', 'Season', true); // outputs 24

See

  • http://de3.php.net/manual/en/function.strstr.php

and the comments on that page to see workarounds for PHP < 5.3

like image 161
Gordon Avatar answered Dec 31 '22 17:12

Gordon


$string="24 Season 1 Episode 3";
$s = explode("Season",$string,2);
echo $s[0];
like image 39
ghostdog74 Avatar answered Dec 31 '22 16:12

ghostdog74