在使用PHP在页面上回显之前,将电子邮件字符串从自定义字段中分离出来


Split email string from custom field before it is echoed on page - using PHP

我习惯于使用javascript来扰乱电子邮件,但我刚刚意识到我在wordpress系统上的电子邮件地址会以完整字符串的形式返回。因此javascript这次帮不了我。

我使用javascript来分割电子邮件地址,但我总是手动分割电子邮件字符串。

请参阅下面我的自定义字段php,它来自wordpress,它反映了一个电子邮件地址。

<?php if (  get_post_meta($post->ID, 'E-mail Address', true) )
    echo get_post_meta($post->ID, 'E-mail Address', true);
?>


我的问题是,在get_post_meta在页面上实际响应之前,是否可以将其拆分?但随后将其以比特形式进行回声。。。像一个阵列。

这是我通常在下面使用的,所以如果可以拆分上面的get_post_meta?

<script type="text/javascript">
<!-- 
// spam protected email
emailE=('david@' + 'example.com')
document.write('<a title="E-mail David" href="mailto:' + emailE + '">' + emailE + '</a>')
 //-->
</script>

未测试:(可能关闭+1个字符)

$emailBeginning = substr(0, strrchr($email, '@')); 
$emailEnd = substr(strrchr($email, '@'), strlen($email));

参考文献(面向未来):

http://php.net/manual/en/function.substr.php

http://www.php.net/manual/en/function.strrchr.php

<?php if (  get_post_meta($post->ID, 'E-mail Address', true) ) { ?>
<?php 
        $email = get_post_meta($post->ID, 'E-mail Address', true);
        $emailSpam = explode("@", $email);
    ?>
    <script type="text/javascript">
        <!-- 
        // spam protected email
        emailE=('<?php echo $emailSpam[0]; ?>' + '@' + '<?php echo $emailSpam[1]; ?>')
        document.write('<a class="exhibitor-links-icon-email" title="Click here to E-mail <?php echo get_the_title(); ?>" href="mailto:' + emailE + '" target="_blank"><img src="<?php bloginfo('template_url'); ?>/images/x.gif" alt="" /></a>')
        //-->
    </script>
<?php } ?>