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,}$",t rim($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
$piece[2]='"-25.53"';
if(ereg("^\-{0,1}[0-9]{0,}
//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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<?
$piece[2]='"-25.53"';
if(ereg("^\"\-{0,1}[0-9]{0 ,}\.{0,1}[ 0-9]{0,}\" $",trim($p iece[2]))) {
print "ok";
}
?>
$piece[2]='"-25.53"';
if(ereg("^\"\-{0,1}[0-9]{0
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
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]
// 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 :)
http://www.php.net/manual/en/pcre.pattern.modifiers.php
http://www.php.net/manual/en/pcre.pattern.syntax.php
http://www.php.net/manual/en/function.preg-match.php
Regards,
Barry