Jump to content

stristr Problem with reading from variable


PdYpsilon

Recommended Posts

Dear people,

 

a priori, iam very bad in english, so pls excuse my bad grammatic.

I have a problem with a function called stristr. I want to search the function for an "@" symbol in a variable, which is filled by an $_POST Value from an formularentry.

Even if I var_dump the variable $mail which has the content of the post-data and is a string, the function still refuses to search for the "at" properly. But if I replace the variable with an direct-typed string, it works. I dont understand that. Here is my script:

 

$form_maill="";
  $error="";
  if (isset($_REQUEST['senden']) && ($_REQUEST['senden'])!=="")
  {
    $error2="";
    $fm=$_POST['form_mail'];
    If(!isset($fm) || ($fm=="") || ($fm=is_array($fm)))
       {
        $error2="1";
        $error="mail";
        $form_maill="<font color="red">*</font>";
       }
       elseif (!(stristr($fm, '@')))
       {
        $error2="1";
        $error="noat";
       }
if($error=="noat") echo "Please type in a correct Emailadress!";
       }

Ok dudes,

 

I fount a weird solution myself.

 

I vardumped the stristr'd variable If the function DONT found an "@". Then it returns boolean false. BUT, and thats the weird thing, If he founds an "@" he dont return true! It returns the string which is the search string "@". Why is that so? Now in my loop I changed the condition from

if (!(stristr($variable, "@"))

 

to

 

$result = stristr($variable, "@");
if ($result !== "@") (

PdYpsilon,

 

I found that your elseif statment was never being hit...

 

Here is code which works as intended...

 

Scot L. Diddle, Richmond VA

 

<?PHP

  $form_maill="";

  $error="";

  $_REQUEST['senden'] = 'test';

  $_POST['form_mail']  = '[email protected]';

  if (isset($_REQUEST['senden']) && ($_REQUEST['senden'])!=="") {

    	$error2="";
   		$fm=$_POST['form_mail'];

    	If(!isset($fm) || ($fm=="") || (is_array($fm))) {

        	$error2="1";
       		$error="mail";

        	$form_maill = "<font color=\"red\">*</font>";

    	 }
     	 else {

     	 	if (!(stristr($fm, '@'))) {
          		$error2="1";
          		$error="noat";

     	 	}

     	}

	    if($error=="noat") {
		        echo "Please type in a correct Emailadress!";
	    }
	    else {
		        echo "Email address is valid...";
	    }

   }

?>

Thank you very Much!

But unfortunately I have another problem with a function. It seems, that iam to stupid to use them or so.

This loop ALWAYS returns false. But that cannot be! Do you know why? Thanx in advance!

 

            
$ft = $_POST['form_text'];
$toomuch = substr_count($ft, 'http');
            if ($toomuch >= 2){
              die("Please only one link per entry!.");
                
            }

 

It returns false if there are no http in the textstring, or if there one or two oder more http. The var_dump of $toomuch returns always int(0). ... :(

 

PdYpsilon,

 

This works:

 

<?php 

	        $ft = $_POST['form_text'];

	        $ft1 = 'http://MyDomain.com';

	        $ft2 = 'http://MyDomain.com http://YourDomain.com';

	        $toomuch1 = substr_count($ft1, 'http');

        if ($toomuch1 >= 2){
            die("Please only one link per entry!.");
        }
        else {
                echo "Right On!"  . "<br /> <br /> \n";
        }
        
	        $toomuch2 = substr_count($ft2, 'http');

        if ($toomuch2 >= 2){
            die("Please only one link per entry!. <br /> <br />");
        }
        else {
            echo "Right On!";
        }
        
?>

 

var_dump($ft) and see what value you are passing to the substr_count() function.

 

Scot

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.