Category Archives: PHP

Fetching data from a CSV file using PHP

To open a CSV file, start by opening the file by using PHP function fopen.

After opening the file (creating file pointer), cycle through the content using fgetcsv function. This function reads the file line by line and parse it based on fields in CSV.

Continue reading Fetching data from a CSV file using PHP

Validating an email address with PHP

Steps to validate an email address:

  1. Sanitizing the email address:
    • strtolower($emailAddress);
    • filter_var($emailAddress, FILTER_SANITIZE_EMAIL); // remove bad characters from the email.
  2. Validating the email adress:
    • filter_var($emailAddress, FILTER_VALIDATE_EMAIL);

Note: For email addresses containing Internationalized Domain Names (IDN) you need to convert it to punycode before validating the email address.