Are there any potential pitfalls when using the explode function in PHP?

One potential pitfall when using the explode function in PHP is that if the delimiter is not found in the input string, the function will return an array with a single element containing the original input string. To avoid this issue, you can check if the exploded array has only one element and handle it accordingly.

$input = "Hello World";
$delimiter = ",";
$exploded_array = explode($delimiter, $input);

if(count($exploded_array) == 1 && $exploded_array[0] == $input) {
    // Handle case where delimiter is not found in input string
    echo "Delimiter not found in input string";
} else {
    // Continue processing the exploded array
    foreach($exploded_array as $value) {
        echo $value . "<br>";
    }
}