What are potential pitfalls when using preg_match() with multiple occurrences of a pattern like "links_end"?

When using preg_match() with multiple occurrences of a pattern like "links_end", the function will only match the first occurrence of the pattern. To match all occurrences, you should use preg_match_all() instead. This function will return all matches in an array, allowing you to iterate over them and process each one individually.

// Example code snippet
$text = "This is a sample text with links_end and links_end";
$pattern = "/links_end/";
preg_match_all($pattern, $text, $matches);

foreach ($matches[0] as $match) {
    echo $match . "\n";
}