What are some possible methods in PHP to extract a substring from a string until the first occurrence of a specific character?
To extract a substring from a string until the first occurrence of a specific character in PHP, you can use the strpos() function to find the position of the character, and then use the substr() function to extract the substring up to that position. This method allows you to easily extract the desired substring from a larger string based on a specific character delimiter.
$string = "Hello, World!";
$delimiter = ",";
$position = strpos($string, $delimiter);
if ($position !== false) {
$substring = substr($string, 0, $position);
echo $substring; // Output: Hello
} else {
echo "Delimiter not found.";
}