Home » Php » php – Can you add multiple values to a string?

php – Can you add multiple values to a string?

Posted by: admin February 25, 2020 Leave a comment

Questions:

foreach(Feed('example.url') as $f ) {
                        if (strpos($f->title, $title) !== false) {
                            $closed_text    = 'closed';
                            $maintenance_text = 'Maintenance';
                            $exception_text = 'could be';

                            if (strpos($f->title, $title) !== false){

                                if(strpos($f->description, $closed_text) !== false){
                                    echo (strpos($f->description, $exception_text) === false) ?
                                        '<span>Closed</span>' :
                                        '<span>Open</span>' ;

                                } else if(strpos($f->description, $maintenance_text) !== false){
                                    echo (strpos($f->description, $exception_text) === false) ?
                                         '<span>Maintenance</span>' :
                                         '<span>Open</span>' ;

                                } else {
                                    echo '<span>Open</span>';
                                }
                            }
                        }
                    }

I want to assign more possible values to $exception_text.

Example:

$exception_text = 'could be' and 'maybe' and 'possibly'; So if one of these word is in the text the if statement is true.

Any help is greatly appreciated!

How to&Answers:

Consider using regex is more appropriate for your case :

$exception_text = '(could be|maybe|possibly)';

if (\preg_match($exception_text, $f->description)) {
    // your stuff
}

With regex you can search multiple pattern in your string.