Created
March 27, 2019 11:59
-
-
Save adamfaux85/a9958a7b4a381d92e491255dcc388160 to your computer and use it in GitHub Desktop.
PHP: Preg replace to add a data attribute to a link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string_raw = '<a href="#">This is an example link</a>'; | |
$string_formatted = preg_replace('/(<a\b[^><]*)>/i', '$1 data-scroll>', $string_raw); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment