What are the potential pitfalls of using explode() function in PHP for handling text fields?

Using the explode() function in PHP for handling text fields can lead to potential pitfalls if the delimiter is not consistent or if the input text contains unexpected characters. To mitigate this issue, it is recommended to validate the input text and handle any edge cases before using explode().

$input_text = "apple,orange,banana";
$delimiter = ",";
if (preg_match('/^[a-zA-Z,]+$/', $input_text)) {
    $text_array = explode($delimiter, $input_text);
    print_r($text_array);
} else {
    echo "Invalid input text.";
}