How can I split email address into different parts of php?

Basically what I want to do is display the email using javascript in order to combine the details and form a complete email address that cannot be seen by the email harvesters.

I would like to get an email address, for example info@thiscompany.com , and break it down into: $ variable1 = "info"; $ variable2 = "thiscompany.com";

All this is done in PHP.

Regards, JB

+3
source share
6 answers

Try this before you start your own (it will be much more):

function hide_email($email)

{ $character_set = '+-.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';

  $key = str_shuffle($character_set); $cipher_text = ''; $id = 'e'.rand(1,999999999);

  for ($i=0;$i<strlen($email);$i+=1) $cipher_text.= $key[strpos($character_set,$email[$i])];

  $script = 'var a="'.$key.'";var b=a.split("").sort().join("");var c="'.$cipher_text.'";var d="";';

  $script.= 'for(var e=0;e<c.length;e++)d+=b.charAt(a.indexOf(c.charAt(e)));';

  $script.= 'document.getElementById("'.$id.'").innerHTML="<a href=\\"mailto:"+d+"\\">"+d+"</a>"';

  $script = "eval(\"".str_replace(array("\\",'"'),array("\\\\",'\"'), $script)."\")"; 

  $script = '<script type="text/javascript">/*<![CDATA[*/'.$script.'/*]]>*/</script>';

  return '<span id="'.$id.'">[javascript protected email address]</span>'.$script;

}
+1
source
list($variable1, $variable2) = explode('@','info@thiscompany.com');
+5
source
$parts = explode("@", $email_address);

, $email_address = 'info@thiscompany.com', $parts[0] == 'info' $parts[1] == 'thiscompany.com'

+2

explode:

$email = 'info@thiscompany.com';

$arr = explode('@',$email);

$part1 = $arr[0]; // info
$part2 = $arr[1]; // thiscompany.com
+2
$email = "info@thiscompany.com";
$parts = explode("@", $email);
+2

How about a function to parse strings according to a given format: sscanf . For instance:

sscanf('info@thiscompany.com', '%[^@]@%s', $variable1, $variable2);
0
source

Source: https://habr.com/ru/post/1741316/


All Articles