Link to home
Start Free TrialLog in
Avatar of baska
baska

asked on

how to check data for double quotes using ereg fn?

hai,
$piece[2]='"-25.53"';
if(ereg("^\-{0,1}[0-9]{0,}\.{0,1}[0-9]{0,}$",trim($piece[2]))){
//other codes
}// this line is to check for the data -25.53.
but I want to check for double quotes also.
so how do I do? anyother alternative code is also welcome.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of axis_img
axis_img

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of axis_img
axis_img

<?
$piece[2]='"-25.53"';
if(ereg("^\"\-{0,1}[0-9]{0,}\.{0,1}[0-9]{0,}\"$",trim($piece[2]))){
    print "ok";
}
?>



I'm curious, us111... Why did you you just post a repeat of my code? Other than the fact that I optimized {0,1} with "?", and removed the unnecessary escaping \ from in front of the -, it is the exact same code. That seems a bit odd to me that you would do that.

Anyway, just another note on using preg_match(). You really should look into it, because ereg() is much much slower.

This is the better option.

if(preg_match("/^\"-?[0-9]*\.?[0-9]*\"$/U", trim($piece[2]))) {
    // other codes
}

If you are not sure about how some of it works, let me know.

Regards,
Barry
hmm well I don't know , sorry  axis_img I was tired :)