129 views

Taking Value Of Attributes inside HTML Tags Using preg_match_all (eg. img src=”")

preg_match_all function matches given parameters inside given string,number,url as in tag we can fetch value of src and stored it in an array

Example:

  1. preg_match_all(‘/ (src)(\=\’|\=\”)([a-zA-Z0-9\-\_\.\/\:]+)\’|\”/’,"<img src=’http://www.computereducationworld.com/logo.jpg’>",$ImagesArray,PREG_SET_ORDER);
  2. print_r($ImagesArray);
  3.  
  4. Output:
  5.  
  6. Array ( [0] =>
  7.  Array (
  8. [0] => src=‘http://www.computereducationworld.com/logo.jpg’
  9. [1] => src
  10. [2] => =
  11. [3] => http://www.computereducationworld.com/logo.jpg
  12. )
  13. )

Post a Comment

You must be logged in to post a comment.