I need to make the PHP below work. I basically need to take a string stored in $sshCommandResponseString and check to see if it contains 1 of 4 possibble strings.
start: Job is already running: mysql
mysql start/running, process 8019
mysql stop/waiting mysql start/running, process 8348
stop: Unknown instance: mysql start/running, process 8693
The last 3 string end with a 4 digit number which will always be a different value. So I cannot do a simple if/else check like the function below does as the string will sometimes end with a 4 digit number!
So what is the best way to check to see if my string matches 1 of these 4 strings?
function didMySqlDbRestart($sshCommandResponseString){
if( $sshCommandResponseString == 'start: Job is already running: mysql' ){
return true;
}else if( $sshCommandResponseString == 'mysql start/running, process 8019' ){
return true;
}else if( $sshCommandResponseString == 'mysql stop/waiting mysql start/running, process 8348' ){
return true;
}else if( $sshCommandResponseString == 'stop: Unknown instance: mysql start/running, process 8693' ){
return true;
}else{
return false;
}
}
if(didMySqlDbRestart($sshCommandResponseString)){
echo 'SUCCESS: MySQL Database Rebooted';
}else{
echo 'ERROR: MySQL Database Did Not Reboot';
}
UPDATE
Adding on to user Laser's answer perhaps something like this would be ok...
function didMySqlDbRestart($sshCommandResponseString){
if(preg_match('/^.*\d{4}$/', trim($sshCommandResponseString)) > 0){
return true;
}else if($sshCommandResponseString == 'start: Job is already running: mysql'){
return true;
}else{
return false;
}
}