Jump to content

PHP eregi not work completed


gongpex
 Share

Recommended Posts

Hello everyone, Long time not meet with you all, but now my connection has return, During I'm offline, I studying about PHP fully and I found trouble on eregi, I had tried using eregi to filter some character like this code :

<?$str ="01234";if(!eregi('^[0-9]',$str)){echo"this is contains alphabetical";}else{echo"correct";}?>

IIf I fill 01234abcdef on $str, it still shown message : "correct", whereas it supposed show "this is contains alphabetical" How to filter so that only using rate character, it can be shown "correct" ? please someone help me Thanks

Link to comment
Share on other sites

^[0-9] it is telling look for character which starts from 0-9. it does not tell how the end should be. so itis showing correct.^[0-9]$ it tell that it should start with 0-9 and it must end with 0-9and also you should not use ereg*() instead use preg_*(). ereg*() are deprecated that means it will be remove from php in future version

Link to comment
Share on other sites

Yes you right thanks for answer, but, with preg_*() can I create email validation ? I don't know how to use preg_*() , because many example but it made me confused, please told me how to make it and a little example about how to use preg_*() Thanks _____________________________________________________________ By the way, can you give me link so that I can download mysqli ?

Edited by gong
Link to comment
Share on other sites

there is not much difference between POSIX and PCRE, both uses same kind of reguler expression syntax.difference is in their implementetion.though http://au2.php.net/m...ttern.posix.php here you can read the differences about both. it is possible to do anything with power of regexp, even email validation. pcre need dilemeters around which means ^[0-9]$ will be $reg="@^[0-9]$@" in pcre. '@' is delimieterhttp://php.net/preg_match <=preg_match() uses and examples general regular expression resource could be found here http://regular-expression.info mysqli comes with general php package which you get from compiled php binaries from php official site. it is also available in other package like xampp,wampp. it always there unless it is not manually compiled with mysqli disabled. so you can check using phpinfo() you have probably already enabled that.

Edited by birbal
Link to comment
Share on other sites

I have tried using preg_match like this code:

if(!preg_match("/@/",$save_email)&$save_email!=""){$warn14 = "<div style=\"color:red;font-size:9px\">Email should be contain "@"</div>";}

but it's didn't show anything, my webpage disappear instead ,and when I delete this code, then my web page appear. Is there some mistake on my code? (on http://php.net/preg_match) I got the example like this:

<?php$str ="aaa@yahoo.com";if (preg_match("/@/", $str)) {  echo "Match was found <br /><br /><br />";}else{echo"this didn't match";}?>

I change this code a little, this is can be run, but when I tried on my project it didn't show anything and cause my web page disappear, and I forgot yesterday , even if I using eregi the result is not complete, this is my code :

<?$str ="01234";if(!eregi('^[0-9]$',$str)){echo"this is contains alphabetical";}else{echo"correct";}?>

It's still show "this is contains alphabetical", supposed it's shown "correct". now what I must do? please help me Thanks

Edited by gong
Link to comment
Share on other sites

if(!preg_match("/@/",$save_email)&&$save_email!=""){$warn14 = "<div style=\"color:red;font-size:9px\">Email should be contain "@"</div>";}you missed it. There is more accurate regex to validate emails.if you google you shoud have found plenty or you can write your own.. above one will also match @yahoo.com,@yahoo,yahoo@ etc etc.

<? $str ="01234"; if(!eregi('^[0-9]$',$str)){ echo"this is contains alphabetical"; }else{ echo"correct"; } ?>
it should be like ^[0-9]$+. ^[0-9]$ will try to match one character "+" will tell to match 1 or more than that. check 'qunatifiers' in "the referece posted in above post.
Link to comment
Share on other sites

Thanks for reply, By the way, about mysqli that shown on phpinfo(), I found result like this : PDO driver enable : sqlite2, Is that support for mysqli? Note : I use apache2 triad 1.5.4 to running application web, is that support mysqli? please answer Thanks ___________________________________________________________________________________________ By the way, is your avatar are your photo?

Edited by gong
Link to comment
Share on other sites

PDO driver enable : sqlite2,
it tells PDO can handle sqlite2. when you are in phpinfo() page, pre ctrl+F type mysqli and you will find mysqli part if it is installed. or you can also run this
echo (string)class_exists("mysqli");

if mysqli is there it will print 1 else it will print 0

I use apache2 triad 1.5.4 to running application web, is that support mysqli?
i have not used it but mysqli is so common extension that it will have it.
By the way, is your avatar are your photo?
yes, it is me. Edited by birbal
Link to comment
Share on other sites

I search using ctrl + F on phpinfo(); but I didn't found 'mysqli', Of course mysqli didn't installed on my apache, What I must do? Please give me advice Thanks _____________________________________________________________________________________ What's your occupation?

Link to comment
Share on other sites

check in your php folder where your php is installed. there should be a directory name ext.open it. can you see anything like php_mysqli.dll? if yes follow step 1 1)open your php.ini which is being loaded you will find lis of extensions there likeextension=php_mysql.dll make sure uncommenting the extension php_mysqli.dll if it is commented. if it is not there put it like extension=php_mysqli.dll else2) you have to compile php with mysqli enabled or you can downlaod compatible shared dll for mysqli and put it in in ext folder (php_mysqli.dll) and then have to follow step 1.

What's your occupation?
i am student of computer science and also persuing a diploma of software engineering Edited by birbal
Link to comment
Share on other sites

I found php_mysqli.dll on folder extension,

open your php.ini which is being loaded you will find lis of extensions there likeextension=php_mysql.dll make sure uncommenting the extension php_mysqli.dll if it is commented. if it is not there put it like extension=php_mysqli.dll
About this step I didn't understand, what the mean of uncommenting? please answer Thanks Edited by gong
Link to comment
Share on other sites

;extension=php_pdo_mysql.dll uncomment means removing the semicolon. ';' used to make comments

Link to comment
Share on other sites

Hello everyone, I tried to combine preg_match() on beginning (^) and the end($) but the result is still not true, this is all of my code that I had tried :

$save_email ="abcdefg01345";if(!preg_match("/[0-9]$/i",$save_email)&&$save_email!=""){$warn14 = "<div style=\"color:red;font-size:9px\">Email should be contain "@"</div>";}

This warn didn't works, but if $save_email ="012345abcdef"; the warn would be works again :

$save_email="01234abcdef";if(!preg_match("/^[0-9]/i",$save_email)&&$save_email!=""){$warn14 = "<div style=\"color:red;font-size:9px\">Email should be contain "@"</div>";}

same too, the warn didn't work, but if $save_email ="abcdefg01345"; the warn would be works and this is fatal error :

$save_email="(everything whether a-z and 0-9)";if(!preg_match("/^[0-9]$/i",$save_email)&&$save_email!=""){$warn14 = "<div style=\"color:red;font-size:9px\">Email should be contain "@"</div>";}

This cause warn running, even if $save_email="012345679", the result warn still running Note : I had tried without using /i character but the result are still same. I don't know what I must do now please help me Thanks

Link to comment
Share on other sites

With this: /[0-9]$/i You're testing if the subject ends with a digit, which it does. With this: /^[0-9]/i You're testing if the subject starts with a digit, which it does. With this: /^[0-9]$/i You're testing if the entire subject is a single digit, that's all. None of those are testing for an email address, you are checking if the subject starts with, ends with, or is a single digit.

Link to comment
Share on other sites

You're testing if the entire subject is a single digit, that's all. None of those are testing for an email address, you are checking if the subject starts with, ends with, or is a single digit.
This is not for email address but for phone number, I'm worried if there is user who ignorant and tried to input data like example on above So, what I must do so that only "Digit" that allowed to pass, and if "letter" not allowed? That's my purpose please help Thanks________________________________________________________________________________________ What's your occupation?
Link to comment
Share on other sites

what I must do so that only "Digit" that allowed to pass, and if "letter" not allowed?
/^[0-9]+$/ it will tell to match numeric number more than one digit. if you need limit in number of digits you can use /^[0-9]{9}$/ for simple case you can use ctype_digit() and strlen() together to match type and length of the string. regexp takes more processing power, so for simple validation it should be avoided.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...