0

I upgraded to PHP 5.3 and i got the error: ereg has been deprecated.

What can i use to replace this??

function CheckIfAlphaNumberic($text) {
    if (ereg('[^A-Za-z0-9]', $text)) {
        unset ($text);
    }
    return $text;
}
Wiseguy
  • 20,522
  • 8
  • 65
  • 81
M. of CA
  • 1,496
  • 2
  • 22
  • 32

3 Answers3

6

You can use preg_match():

function CheckIfAlphaNumberic($text){
    if (preg_match('#[^A-Za-z0-9]#', $text)) {
        unset ($text);
    }
    return $text;
}

See also: Switching From ereg to preg

Furthermore, you may use return null; instead of unset ($text);

Floern
  • 33,559
  • 24
  • 104
  • 119
4

See what it says on the php site:

It recommends using preg_match()

Naftali
  • 144,921
  • 39
  • 244
  • 303
  • 1
    +1 Though next time please just quote the text (by preceding it with an `>`) instead of inserting an image :) It's pretty hard to read what the image says as it is resized. – NikiC Jun 16 '11 at 19:59
1

use preg_match

http://www.php.net/manual/en/function.preg-match.php

Headshota
  • 21,021
  • 11
  • 61
  • 82