Jump to content

basic function not working


blueman378

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.