fork download
  1. <?php
  2.  
  3. $text = "<b>lorem</b>
  4. description 1
  5.  
  6. <b>lorem</b>
  7. description 2
  8.  
  9. <b>lorem</b>
  10. description 3
  11.  
  12. <b>lorem</b>
  13. description 4
  14.  
  15. <b>lorem</b>
  16. description 5
  17.  
  18. <b>lorem</b>
  19. description 6";
  20.  
  21.  
  22. $i = 1;
  23. $matches = null;
  24.  
  25. while (true) {
  26.  
  27. $text = preg_replace('|<(/)?b>|', ('<\1h'.$i.'>'), $text, 2, $matches);
  28.  
  29. if (!$matches) {
  30. break;
  31. }
  32.  
  33. if ($i < 4) $i++;
  34. $matches = null;
  35.  
  36. }
  37.  
  38. echo $text;
  39.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
<h1>lorem</h1>
description 1

<h2>lorem</h2>
description 2

<h3>lorem</h3>
description 3

<h4>lorem</h4>
description 4

<h4>lorem</h4>
description 5

<h4>lorem</h4>
description 6