Advertisement
adilmchoudhury

Code extract

Nov 23rd, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2. // Array to store data attribute values
  3. $dataArray = array();
  4.  
  5. // Your HTML with object tags
  6. $html = '
  7.  
  8. <object data="https://lh3.googleusercontent.com/pw/ADCreHftjFHGck3jAfULwxkYHZwONXzrWPTNyHjkR5HSPFbIbLNYe_p4vq07qD5OpcpUVS5DvJC35gEyS2C5MMM2jY57-T1zRdZL2x-HLX4kUvtr-qtbNLAa=w1920-h1080"></object>
  9. <object data="https://lh3.googleusercontent.com/pw/ADCreHfh1X0-aveKY7t_czfeMtGLWm3T5Fjb-0jSfx-EpCB3M4fRq9LQPALZR1s9Elyn63YKhdzP7YUX-7VXIyWseTt-IxZu0Umz7x4MS53ZcJFlYNZvw7Xf=w1920-h1080"></object>
  10. <object data="https://lh3.googleusercontent.com/pw/ADCreHeQC0Jm7crtJs2rdlYgr16aWobX4tDMC4ru6JesUqri33b5yNmMOObK-F1UM-ANycHQ_q8WSuX0qi6hxbzKM5kks2O2pR5caFEry1CvtI0lxC9QHDDS=w1920-h1080"></object>
  11.  
  12. ';
  13.  
  14. // Parsing HTML to get data attribute values
  15. $doc = new DOMDocument();
  16. $doc->loadHTML($html);
  17.  
  18. // Get all <object> tags
  19. $objects = $doc->getElementsByTagName('object');
  20.  
  21. // Loop through each <object> tag and extract data attribute values
  22. foreach ($objects as $object) {
  23. $data = $object->getAttribute('data');
  24. // Add data attribute value to the PHP array
  25. $dataArray[] = $data;
  26. }
  27.  
  28. // Printing the PHP array with data attribute values
  29. //print_r($dataArray);
  30.  
  31. // Loop through the array and print each item inside the HTML structure
  32. foreach ($dataArray as $data) {
  33. echo '<a href="' . $data . '"><img src="' . $data . '" alt="" title=""/></a><br>';
  34. }
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement