fork download
  1. <?php
  2.  
  3. $data = $data = 'THE CORRECT ANSWER IS C.
  4. <p>
  5. Choice A Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s
  6. </p>
  7. <p></p>
  8. <p>
  9. Choice B Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s
  10. </p>
  11. <p>
  12. Choice D Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s
  13. </p>
  14. <p></p>
  15. <p>
  16. Choice E simply dummy text of the printing and typesetting industry.
  17. </p>
  18. <p></p>
  19. <p>
  20. <br>
  21. THIS IS MY MAIN TITLE IN CAPS
  22. <br>
  23. This my sub title.
  24. </p>
  25. <p>
  26. <br>
  27. TEST ABC: Lorem Ipsum is simply dummy text of the printing and typesetting industry.
  28. </p>
  29. <p>
  30. <br>
  31. TEST XYZ: Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
  32. </p>
  33. <p>
  34. <br>
  35. TES T TEST: It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
  36. </p>
  37. <p>
  38. <br>
  39. TESTXXX: It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';
  40.  
  41. $dom = new DOMDocument();
  42. $dom->loadHTML($data, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  43. $xpath = new DOMXPath($dom);
  44. foreach($xpath->query('//text()') as $node) {
  45. $txt = trim($node->nodeValue);
  46. $p = $node->parentNode;
  47. if (preg_match("/^\s*(TEST ABC:|TEST XYZ:|TES T TEST:|TESTXXX)(.*)$/s", $node->nodeValue, $matches)) {
  48. // Put Choice X in bold:
  49. $p->insertBefore($dom->createElement('strong', $matches[1]), $node);
  50. $node->nodeValue = " " . trim($matches[2]);
  51. } else if (strtoupper($txt) === $txt && $txt !== '') {
  52. // Put header in bold
  53. $p->insertBefore($dom->createElement('strong', $txt), $node);
  54. $node->nodeValue = "";
  55. }
  56. }
  57. $data = $dom->saveHTML();
  58.  
  59. echo $data;
  60.  
  61. ?>
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
<p><strong>THE CORRECT ANSWER IS C.</strong><p>
    Choice A Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s
    </p><p></p><p>
    Choice B Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s
    </p><p>
    Choice D Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s
    </p><p></p><p>
    Choice E simply dummy text of the printing and typesetting industry.
    </p><p></p><p>
    <br><strong>THIS IS MY MAIN TITLE IN CAPS</strong><br>
    This my sub title.
    </p><p>
    <br><strong>TEST ABC:</strong> Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><p>
    <br><strong>TEST XYZ:</strong> Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p><p>
    <br><strong>TES T TEST:</strong> It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p><p>
    <br><strong>TESTXXX</strong> : It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p></p>