Skip to content

Instantly share code, notes, and snippets.

@hlashbrooke
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlashbrooke/459b74a66442422d3460 to your computer and use it in GitHub Desktop.
Save hlashbrooke/459b74a66442422d3460 to your computer and use it in GitHub Desktop.
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