Not sure how you define "phrase that ends"... But if you means "a sentence ends with the password, but could be followed by another sentence", then a solution could be :
$text = <<<TEXT
This is some
text and there is a sentence that ends
with WITH PASSWORD kEqHqPUd. Is that
matched ?
TEXT;
$matches = array();
if (preg_match('/WITH PASSWORD ([\w\d]+)/', $text, $matches)) {
var_dump($matches[1]);
}
This will only work, though, if the password only contains letters and/or numbers -- but will work if there is something after "the end of the phrase".
If you meant that the password is the last thing in the whole string, you could use something like this :
$text = <<<TEXT
This is some
text and there is a sentence that ends
with WITH PASSWORD kEqHqPUd
TEXT;
$matches = array();
if (preg_match('/WITH PASSWORD (.+)$/m', $text, $matches)) {
var_dump($matches[1]);
}
Note that the $
sign means "end of string".