What are some alternative methods to extract data from a string in PHP besides using regular expressions?

When extracting data from a string in PHP, besides using regular expressions, you can also use functions like explode(), substr(), strpos(), and strstr(). These functions can help you extract specific parts of a string based on delimiters, positions, or substrings without the complexity of regular expressions.

// Using explode() to extract data from a string based on a delimiter
$string = "apple,orange,banana";
$data = explode(",", $string);
print_r($data);

// Using substr() to extract a specific portion of a string
$string = "Hello World";
$data = substr($string, 6, 5);
echo $data;

// Using strpos() and substr() to extract data based on position
$string = "Hello World";
$position = strpos($string, "W");
$data = substr($string, $position);
echo $data;

// Using strstr() to extract data from a string starting from a specific substring
$string = "Hello World";
$data = strstr($string, "W");
echo $data;