blueman378 Posted May 14, 2008 Share Posted May 14, 2008 hi guys, well im having some problems with my code, valclass.php <?php class validate { function valemail($email) { if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) { return FALSE; } list($Username, $Domain) = split("@",$email); if(getmxrr($Domain, $MXHost)) { return $email; } } function valtext($string) { $string = trim(htmlentities($string, ENT_COMPAT)); $p = array( "<b>", "</b>", "<strong>", "</strong>", "<u>", "</u>", "<i>", "</i>" ); $q = array( "<strong>", "</strong>", "<strong>", "</strong>", "<u>", "</u>", "<i>", "</i>" ); $string = preg_replace($p, $q, $string); return $string; } } $validate = new validate; //CALLING THE Product Admin CLASS ?> index.php <?php include("valclass.php"); $a = "<b>Hello i @m matthew</b><strong>lol</strong>"; echo $validate->valtext($a); ?> error: Warning: preg_replace() [function.preg-replace]: Unknown modifier 'g' in C:\Users\Matthew\websites\ecommerce\valclass.php on line 35 that line is the line that instigates the preg replace Link to comment https://forums.phpfreaks.com/topic/105547-basic-function-not-working/ Share on other sites More sharing options...
mraiur Posted May 14, 2008 Share Posted May 14, 2008 hmm try $new_class =& new validate(); first and then call the preg_replace function i think its better to name your variables longer then with on letter . Link to comment https://forums.phpfreaks.com/topic/105547-basic-function-not-working/#findComment-540686 Share on other sites More sharing options...
blueman378 Posted May 14, 2008 Author Share Posted May 14, 2008 ignore the fact that it is simply called a thats jsut for testing purposes, well heres a updated code [thanks Rajiv] <?php class validate { function valemail($email) { //Assumes that valid email addresses consist of [email protected] $at = strpos($email, "@"); $dot = strrpos($email, "."); if($at === false || $dot === false || $dot <= $at + 1 || $dot == 0 || $dot == strlen($email) - 1) return "Invalid Email"; $user_name = substr($email, 0, $at); $domain_name = substr($email, $at + 1, strlen($email)); $user_name = trim(htmlentities($user_name, ENT_COMPAT)); $domain_name = trim(htmlentities($domain_name, ENT_COMPAT)); $email = $username+@+$domain_name; return $email; } function valtext($string) { $string = trim(htmlentities($string, ENT_COMPAT)); $p = array( "#<b>#", "#</b>#", "#<strong>#", "#</strong>#", "#<u>#", "#</u>#", "#<i>#", "#</i>#" ); $q = array( "<strong>", "</strong>", "<strong>", "</strong>", "<u>", "</u>", "<i>", "</i>" ); $string = preg_replace($p, $q, $string); return $string; } } $validate = new validate; //CALLING THE Product Admin CLASS ?> whick works fine, but now as you can see im working on the email valdation, its semi working, if it is invalid Invalid email is returned, however if it is valid the script is echoing 0, any ideas why? Link to comment https://forums.phpfreaks.com/topic/105547-basic-function-not-working/#findComment-540695 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.