I have a string:
HELLO WORLD by Adam Smith published 1920 born 1890;
How I can check that year after 'born' 1890 not greater then year after published 1920? Thanks
To compare numbers with numbers, check: http://php.net/manual/en/language.operators.comparison.php
Regular expressions would do the trick to extract the 2 numbers from a string and then you compare the 2 numbers. See Extract numbers from a string
Use regular expression to extract the digits from the letters and compare:
$str="HELLO WORLD by Adam Smith published 1920 born 1890";
$patt="/\d{4}/";
$res=preg_match_all($patt,$str,$matches);
if($matches[0] > $matches[1]){
echo 'Year of birth is before year of publishing';
}else{
echo 'Looks like time travelling: published before even born ...';
}
$matches holds: Array ( [0] => Array ( [0] => 1920 [1] => 1890 ) )
The preg_match_all function extracts all 4 digit character chain and lays that into the array $matches. But you have to be sure, that the sentence has no other year (or 4 digit stings) and that the published date is the first and birth date second argument in the sentence.