You can use PHP's regular expression functions. preg_match_all() Matches all image links in the article; the regular expression can be used to match these links based on their format.
Here is an example:
function getImagesFromContent($content) {
$pattern = '/<img.*?src=[\'"](.*?)[\'"].*?>/i';
preg_match_all($pattern, $content, $matches);
return $matches[1];
}This function takes a string parameter. $contentRepresents the article content; it uses regular expressions. /<img.*?src=[\'"](.*?)[\'"].*?>/i Match all image links within the article..*? Matches zero or more occurrences of any character (including whitespace); use. ? Indicates the non-greedy mode (matches as few characters as possible);[\'"] Indicates matching single or double quotation marks;i Indicates case insensitivity. Matching results will be saved. $matches The second element of the array $matches[1] The function returns this array.
Example usage:
$content = '<p><img src="https://example.com/image1.jpg" /></p>
<p><img src="https://example.com/image2.jpg" /></p>
<p><img src="https://example.com/image3.jpg" /></p>';
$images = getImagesFromContent($content);
var_dump($images);Output result:
array(3) {
[0]=>
string(24) "https://example.com/image1.jpg"
[1]=>
string(24) "https://example.com/image2.jpg"
[2]=>
string(24) "https://example.com/image3.jpg"
}