Are there any potential pitfalls to be aware of when extracting URLs from text in PHP?
One potential pitfall when extracting URLs from text in PHP is that the regular expression used to match URLs may not cover all possible variations of URLs, leading to some URLs being missed or incorrectly extracted. To avoid this issue, it is recommended to use a robust regular expression pattern that can accurately match various types of URLs.
$text = "Check out this website: https://www.example.com";
preg_match_all('/https?:\/\/\S+/', $text, $matches);
$urls = $matches[0];
foreach ($urls as $url) {
echo $url . "\n";
}