How can one ensure that the extracted substring from a string in PHP is always the first part before a specific delimiter?

When extracting a substring from a string in PHP before a specific delimiter, you can use the `explode()` function to split the string into an array based on the delimiter and then access the first element of the array to get the desired substring. To ensure that the extracted substring is always the first part before the delimiter, you need to make sure that the delimiter exists in the original string before performing the extraction.

$string = "Hello World! This is a test";
$delimiter = "!";
$parts = explode($delimiter, $string);
$substring = $parts[0];

echo $substring; // Output: Hello World