1

I'm running a check on a retrieved biography string to find out if an artist is still active.

example bio:

$bio = 'Band was a psychedelic/progressive rock band';

At the moment I have

$active = (strpos($bio, 'was an')) ? false : true;

But I also want to check for other occurrences. Like:

$inactives = array('was a', 'was an', 'died', 'were a');  

Is there a simple way of doing this without the use of a loop? So if the bio string contains any values that are inside the inactives array then return false.

1

1 Answer 1

4

Try this regex approach:

if(preg_match('~(was a|was an|died|were a|were an)~', $input)) {
    echo 'not active anymore';
}

or simpified:

if(preg_match('~(was an?|died|were an?)~', $input)) {
    echo 'not active anymore';
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.