User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » PHP6 - ereg to preg and filter_var Page [1]  
quagmire02
All American
44225 Posts
user info
edit post

since PHP6 won't support ereg at all, i had a bit of free time to go through the code on all my websites to convert ereg to preg (which, for the most part, isn't especially difficult)...since i tend to reuse functions pretty regularly, it's not a big chore

i do, however, have this line in my email-checking function that is giving me trouble, but that's because i don't know my regex as well as i should:

ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",$local_array[$i])
converting it to preg_match causes problems with the =
preg_match("/^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/i",$local_array[$i])
suggestions?

also, the reason i didn't put this into the regex thread is because i was going to ask advice on the filter_var function that was new in 5.2.0...anyone using it? any reason NOT to use it?

here's a list of constants, if anyone's interested:

http://mattiasgeniar.be/2009/02/07/input-validation-using-filter_var-over-regular-expressions/

[Edited on November 6, 2009 at 2:33 PM. Reason : spacing]

11/6/2009 2:32:55 PM

Novicane
All American
15416 Posts
user info
edit post

i thought you could still use eregi?

this is currently working for me (file uploads):


if (eregi('(.jpg)|(.jpeg)^', $sFileName)) {
$sMimeType = 'image/jpeg';

11/6/2009 3:26:42 PM

quagmire02
All American
44225 Posts
user info
edit post

^ on PHP6?

11/6/2009 3:29:40 PM

Novicane
All American
15416 Posts
user info
edit post

oh sorry 4.3.10 >.<

11/6/2009 4:46:01 PM

BigMan157
no u
103354 Posts
user info
edit post

sweet, i didn't know about the filter_var thing

preg_match("/^(([A-Za-z0-9!#$%&'*+\/=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/i",$local_array[$i])


[Edited on November 6, 2009 at 7:16 PM. Reason : also, you need to escape the / before the = in your new statement]

[Edited on November 6, 2009 at 7:19 PM. Reason : you may have to escape the ^,$, and ? too]

11/6/2009 7:16:17 PM

quagmire02
All American
44225 Posts
user info
edit post

Quote :
"sweet, i didn't know about the filter_var thing "

inorite...it's pretty cool stuff

Quote :
"also, you need to escape the / before the = in your new statement"

ah, i think this will do it

Quote :
"you may have to escape the ^,$, and ? too"

i don't think so, based on the other bits i've converted, but i'll keep it in mind

thanks!

11/6/2009 7:30:34 PM

 Message Boards » Tech Talk » PHP6 - ereg to preg and filter_var Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.