Skip to content

Instantly share code, notes, and snippets.

@hlashbrooke
Last active August 29, 2015 14:04
Embed
What would you like to do?
Function to prevent numbers (or any other string) from being automatically turned into a link inside Gmail, Outlook, etc.
<?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