Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9071801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:00:27+00:00 2026-06-16T18:00:27+00:00

Got this warning when I check whether the credit card number is valid or

  • 0

Got this warning when I check whether the credit card number is valid or not. Calling creditcard_helper.php by using the statement if(card_number_valid($this->input->post('card_number'))!=1)

A PHP Error was encountered

Severity: 8192

Message: Function ereg_replace() is deprecated

Filename: helpers/creditcard_helper.php

Line Number: 51

creditcard_helper.php

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* Credit Card Functions
*
* This helper module contains functions which can be used to manipulate credit
* card numbers and related information.
*
* @package    CodeIgniter
* @subpackage    Helpers
* @category    Helpers
* @author    Jim O'Halloran
*/


/**
* Truncates a card number retaining only the first 4 and the last 4 digits.  It then returns the truncated form.
*
* @param string The card number to truncate.
* @return string The truncated card number.
*/
function truncate_card($card_num) {
    $padsize = (strlen($card_num) < 7 ? 0 : strlen($card_num) - 7);
    return substr($card_num, 0, 4) . str_repeat('X', $padsize). substr($card_num, -3);
}


/**
* Validates a card expiry date.  Finds the midnight on first day of the following
* month and ensures that is greater than the current time (cards expire at the
* end of the printed month).  Assumes basic sanity checks have already been performed
* on month/year (i.e. length, numeric, etc).
*
* @param integer The expiry month shown on the card.
* @param integer The expiry year printed on the card.
* @return boolean Returns true if the card is still valid, false if it has expired.
*/
function card_expiry_valid($month, $year) {
    $expiry_date = mktime(0, 0, 0, ($month + 1), 1, $year);
    return ($expiry_date > time());
}


/**
* Strips all non-numerics from the card number.
*
* @param string The card number to clean up.
* @return string The stripped down card number.
*/
function card_number_clean($number) {
    return ereg_replace("[^0-9]", "", $number);
}


/**
* Uses the Luhn algorithm (aka Mod10) <http://en.wikipedia.org/wiki/Luhn_algorithm>
* to perform basic validation of a credit card number.
*
* @param string The card number to validate.
* @return boolean True if valid according to the Luhn algorith, false otherwise.
*/
function card_number_valid ($card_number) {
    $card_number = strrev(card_number_clean($card_number));
    $sum = 0;

    for ($i = 0; $i < strlen($card_number); $i++) {
      $digit = substr($card_number, $i, 1);

        // Double every second digit
        if ($i % 2 == 1) {
          $digit *= 2;
        }

        // Add digits of 2-digit numbers together
        if ($digit > 9)    {
          $digit = ($digit % 10) + floor($digit / 10);
        }

        $sum += $digit;
    }

    // If the total has no remainder it's OK
    return ($sum % 10 == 0);
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:00:28+00:00Added an answer on June 16, 2026 at 6:00 pm

    Please use

    preg_replace()
    

    instead of

    ereg_replace()
    

    This function has been DEPRECATED as of PHP 5.3.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this warning: 'UIView' may not respond to 'addSubview:withAnimation:' The line of code
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
I ran a Code Analysis and got this message: Warning 5 CA1822 : Microsoft.Performance
While compiling a program in Java I got this big WARNING warning: [unchecked] unchecked
Got this line of code here but its not working. private void Button_Click(object sender,
I've got the following function which i'm using to check if a directory is
I just started up django-celery and got this warning: DeprecationWarning: The `celery.decorators` module and
Anyone knows what this mean? Care to shed some light? Got this warning while
Warning: very outdated question with an awful idea. Storing code, whether it be PHP,
I want to check whether the user input contains only digits or not. So,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.