Function to prevent numbers (or any other string) from being automatically turned into a link inside Gmail, Outlook, etc.
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 | |
function prevent_text_link( $str ) { | |
// Get total length of string | |
$strlen = strlen( $str ); | |
// Get number of middle character in string | |
$middle = round( intval( $strlen ) / 2 ); | |
// Loop through each character in the string and add an empty HTML tag in the middle | |
$output = ''; | |
for( $i = 0; $i <= $strlen; $i++ ) { | |
$char = substr( $str, $i, 1 ); | |
if( $middle == $i ) { | |
$output .= '<em></em>'; | |
} | |
$output .= $char; | |
} | |
return $output; | |
} | |
// $string is the original string and $formatted_string is the modified one that can be used in the email | |
$formatted_string = prevent_text_link( $string ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment