What is the purpose of extracting embed code src links using regex in PHP?

When working with HTML content in PHP, you may need to extract the src links from embed code (such as <iframe> or <video> tags) for various purposes, such as parsing or modifying the content. Using regular expressions (regex) is a common approach to achieve this, as it allows you to match specific patterns within the HTML code and extract the necessary src links.

&lt;?php
$html = &#039;&lt;iframe src=&quot;https://www.example.com/embed/video&quot;&gt;&lt;/iframe&gt;&#039;;
$embed_src = &#039;&#039;;

// Use regex to extract src link from embed code
if (preg_match(&#039;/&lt;iframe.*?src=[&quot;\&#039;]([^&quot;\&#039;]*)[&quot;\&#039;].*?&gt;/i&#039;, $html, $matches)) {
    $embed_src = $matches[1];
}

echo $embed_src; // Output: https://www.example.com/embed/video
?&gt;