fork download
  1. <?php
  2. $string = "
  3. <p> some text</p>
  4. <h3>h3 text1</h3>
  5. <p> some text</p>
  6. some text
  7. <h3>h3 text2</h3>
  8. <h3>h3 text3</h3>
  9. ........
  10. ";
  11. '|<h3>(.*?)</h3>|',
  12. function ($matches)
  13. {
  14. //return getSlug($matches[0]);
  15. return '<a href="#'.$matches[1].'">'.$matches[1].'</a>';
  16. },
  17. $string
  18. );
  19. echo $string;
  20.  
  21. ?>
  22.  
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
    <p> some text</p>
    <a href="#h3 text1">h3 text1</a>
    <p> some text</p>
    some text
    <a href="#h3 text2">h3 text2</a>
    <a href="#h3 text3">h3 text3</a>
    ........