DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Building the World's Most Resilient To-Do List Application With Node.js, K8s, and Distributed SQL
  • Why You Should Consider Using React Router V6: An Overview of Changes
  • A Data-Driven Approach to Application Modernization
  • The Role of AI and Programming in the Gaming Industry: A Look Beyond the Tables

Trending

  • Building the World's Most Resilient To-Do List Application With Node.js, K8s, and Distributed SQL
  • Why You Should Consider Using React Router V6: An Overview of Changes
  • A Data-Driven Approach to Application Modernization
  • The Role of AI and Programming in the Gaming Industry: A Look Beyond the Tables
  1. DZone
  2. Coding
  3. Languages
  4. Encode Email Addresses With PHP

Encode Email Addresses With PHP

Paul Underwood user avatar by
Paul Underwood
·
Mar. 20, 13 · Interview
Like (0)
Save
Tweet
Share
8.66K Views

Join the DZone community and get the full member experience.

Join For Free

Spam bots will crawl your pages exactly the same way Search Engines crawls your pages, but while Search Engines are crawling to index your content, spam bots are crawling to find certain information.

One of the most common bits of data they are searching for are email addresses, this is because they can store these email addresses in a list and send out spam emails.

Displaying your email address on your web page makes it very easy for your visitors to store this and send you email, but you will need to get around the spam bot problem to do this you will need to HTML encode your email address.

While encoding your email address will make it display correctly in the browser in the source code the email address will be encoded so that spam bots can not read the email.

Below is a PHP code snippet which will allow you to pass in an email address and encode it so that you can display the email address on your website. This uses the PHP function ord() to return an ASCII value for the character used in the email.

/**
 * Encode an email address to display on your website
 */
function encode_email_address( $email ) {
     $output = '';
     for ($i = 0; $i < strlen($email); $i++)
     {
          $output .= '&#'.ord($email[$i]).';';
     }
     return $output;
}

To use in on your page all you have to do is pass in a parameter and it will return the encoded email you can now use on your website.

$encodedEmail = encode_email_address( 'example@domain.com' );
printf('<a href="mailto:%s">%s</a>', $encodedEmail, $encodedEmail);




PHP

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Building the World's Most Resilient To-Do List Application With Node.js, K8s, and Distributed SQL
  • Why You Should Consider Using React Router V6: An Overview of Changes
  • A Data-Driven Approach to Application Modernization
  • The Role of AI and Programming in the Gaming Industry: A Look Beyond the Tables

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: