Created
January 5, 2023 07:05
-
-
Save sabbir1991/1259ea8f06956d847366d55b9266553e to your computer and use it in GitHub Desktop.
Replace anchor tag content depending on specific attributes.
This file contains hidden or 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
$input_lines = '<a href="index.php" target="_blank" class="link testing" >Test Link</a><a href="index.php" class="link testing" target="_blank" >Test Link</a><a href="index.php" target="_blank" class="link testing" >Test Link</a>'; | |
$replace_text = preg_replace('/(\<a.*?target=\"_blank\".*?>)(.*?)(\<\/a\>)/', '$1$2<span>screen reader</span>$3', $input_lines); | |
echo $replace_text; | |
// Output... | |
<a href="index.php" target="_blank" class="link testing" >Test Link<span>screen reader</span></a> | |
<a href="index.php" class="link testing" target="_blank" >Test Link<span>screen reader</span></a> | |
<a href="index.php" target="_blank" class="link testing" >Test Link<span>screen reader</span></a> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment