fork(2) download
  1. <?php
  2. $html = <<<DATA
  3. <html>
  4.  <head><title>Nice page</title></head>
  5. <body>
  6.   Hello World
  7.  <a href=http://c...content-available-to-author-only...n.com title="a link">
  8.   this is a link
  9.  </a>
  10. <br />
  11. <a href=http://w...content-available-to-author-only...n.com> Here too <img src=wrong.image title="and again">
  12.   <span>Even that<div title="same">all the same</div></span>
  13. </a>
  14. </body>
  15. </html>
  16. DATA;
  17.  
  18. $dom = new DOMDocument('1.0', 'UTF-8');
  19. $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  20.  
  21. $xpath = new DOMXPath($dom);
  22. $titles = $xpath->query('//a[@title]');
  23.  
  24. foreach($titles as $title) {
  25. $title->setAttribute("title", mb_strtoupper($title->getAttribute("title"), 'UTF-8'));
  26. }
  27.  
  28. echo $dom->saveHTML();
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
<html>
 <head><title>Nice page</title></head>
<body>
    Hello World
 <a href="http://c...content-available-to-author-only...n.com" title="A LINK">
                this is a link
 </a>
<br>
<a href="http://w...content-available-to-author-only...n.com"> Here too <img src="wrong.image" title="and again">
    <span>Even that<div title="same">all the same</div></span>
</a>
</body>
</html>