16c05-1.php
来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 32 行
PHP
32 行
<?php// A function that will protect email addreses, by generating JavaScript, // which will in turn generate the Email Link!function write_protected_email($address) { // Generate the full link: $link = "<a href=\"mailto:{$address}\">{$address}</a>"; // Loop through the string, creating an array of codes: $codes = array(); for ($i = 0; $i < strlen($link); $i++) { // Use 'ord' to convert the character to it's ascii value $codes[] = ord($link{$i}); } // Ok, now echo out the JavaScript needed to recreate. // Essentially is just the array, and a loop to print it out: // Make the array first: $outputarray = implode(',', $codes); // Now echo it and we are done. echo "<script>var datapoints = new Array({$outputarray});for (var i = 0; i < datapoints.length; i++) { document.write(String.fromCharCode(datapoints[i])); }</script>";}// Test this to see if it works:write_protected_email('Francesca_Angelo@example.com');?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?