How can the explode() function be used to split a string in PHP and what are some potential pitfalls to be aware of?

The explode() function in PHP can be used to split a string into an array based on a specified delimiter. To use explode(), simply pass the delimiter as the first argument and the string to be split as the second argument. It is important to be aware of potential pitfalls such as not handling cases where the delimiter may not exist in the string, leading to unexpected results.

$string = "Hello,World,PHP";
$delimiter = ",";
$array = explode($delimiter, $string);

print_r($array);