Results 1 to 2 of 2

Thread: Your commonly used functions PHP

  1. #1
    Flash M0nkey
    Join Date
    Sep 2001

    Your commonly used functions PHP

    Ok we all have some lil snippets of code we fall back on time-&-time again so I thought would be a nice idea to share some of them out

    So I'll start it of......

    this is a simple function I cobbled together after reading some tuts on validating email adresses with PHP

    It checks email formatting and also that domain exsists - not foolproof but should help weed out things like adflhad@asdfhlsd.com

    //check email is valid format
    function emailsyntax_is_valid($email) {
      $to_work_out = explode("@", $email);
      if (!isset($to_work_out[0])) return FALSE;
      if (!isset($to_work_out[1])) return FALSE;
      $pattern_local = '^([0-9a-z]*([-|_]?[0-9a-z]+)*)(([-|_]?)\.([-|_]?)[0-9a-z]*([-|_]?[0-9a-z]+)+)*([-|_]?)$';
      $pattern_domain = '^([0-9a-z]+([-]?[0-9a-z]+)*)(([-]?)\.([-]?)[0-9a-z]*([-]?[0-9a-z]+)+)*\.[a-z]{2,4}$';
      $match_local = eregi($pattern_local, $to_work_out[0]);
      $match_domain = eregi($pattern_domain, $to_work_out[1]);
      if ($match_local && $match_domain) {
      	list($user, $domain) = split("@", $email, 2);
          if (! checkdnsrr($domain, "MX")) {
            return FALSE;
        return TRUE;
      return FALSE;

  2. #2
    Senior Member
    Join Date
    Feb 2004
    not really a function but more a snippet of code

    while($row = mysql_fetch_array($result)) {
    echo '<tr>';
    for($i = 0; $i < count($row); $i++) {
    echo '<td>'.$row[$i].'</td>';
    echo '</tr>';
    echo '</table>';

    adepted many times but still remaining one of my most used pieces of code.
    Since the beginning of time, Man has searched for the answers to the big questions: \'How did we get here?\' \'Is there life after death?\' \'Are we alone?\' But today, in this very theatre, you will be asked to answer the biggest question of them all...WHO LIVES IN A PINEAPPLE UNDER THE SEA?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts