Guest User

Untitled

a guest
Jan 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. $text = '<p>This is a</p>
  2. <h1>Test</h1>
  3. <p>to see if this works </p>';
  4.  
  5. $regex = '/<h([0-6]{1})>(.+)</h[0-6]{1}>/';
  6.  
  7. echo preg_replace($regex, '<h$1><a name="$2">$2</a></h$1>', $text);
  8.  
  9. <p>This is a</p>
  10. <h1><a name="Test">Test</a></h1>
  11. <p>to see if this works </p>
  12.  
  13. Header 1 {#header1}
  14. ========
  15.  
  16. ## Header 2 ## {#header2}
  17.  
  18. [Link back to header 1](#header1)
Add Comment
Please, Sign In to add comment