Finding all pictures in text. Parsing.
Find all img images in text, php regular expression. All images are included in the array.
/* preg_match_all match the regexp in all the $html string and output everything as an array in $result. "i" option is used to make it case insensitive */ preg_match_all('/<img[^>]+>/i',$html, $result); print_r($result); Array ( [0] => Array ( [0] =>[1] =>
[2] =>
[3] => [4] =>
[...] ) )
To parse all images into alt attributes, title, src you can use another regular expression:
$img = array(); foreach( $result as $img_tag) { preg_match_all('/(alt|title|src)=("[^"]*")/i',$img_tag, $img[$img_tag]); }
The result of executing a regular expression for an array of images.
print_r($img); Array ( [] => Array ( [0] => Array ( [0] => src="/Content/Img/stackoverflow-logo-250.png" [1] => alt="logo link to homepage" ) [1] => Array ( [0] => src [1] => alt ) [2] => Array ( [0] => "/Content/Img/stackoverflow-logo-250.png" [1] => "logo link to homepage" ) )
And so on …
You can also use the HTML code parser PHP Simple HTML DOM Parser
/*

- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.
[1] =>
[2] =>
[3] =>
[4] => 



