PdYpsilon Posted June 20, 2008 Share Posted June 20, 2008 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!"; } Link to comment https://forums.phpfreaks.com/topic/111093-stristr-problem-with-reading-from-variable/ Share on other sites More sharing options...
PdYpsilon Posted June 20, 2008 Author Share Posted June 20, 2008 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 !== "@") ( Link to comment https://forums.phpfreaks.com/topic/111093-stristr-problem-with-reading-from-variable/#findComment-570115 Share on other sites More sharing options...
ScotDiddle Posted June 20, 2008 Share Posted June 20, 2008 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..."; } } ?> Link to comment https://forums.phpfreaks.com/topic/111093-stristr-problem-with-reading-from-variable/#findComment-570123 Share on other sites More sharing options...
PdYpsilon Posted June 20, 2008 Author Share Posted June 20, 2008 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). ... Link to comment https://forums.phpfreaks.com/topic/111093-stristr-problem-with-reading-from-variable/#findComment-570214 Share on other sites More sharing options...
ScotDiddle Posted June 20, 2008 Share Posted June 20, 2008 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 Link to comment https://forums.phpfreaks.com/topic/111093-stristr-problem-with-reading-from-variable/#findComment-570538 Share on other sites More sharing options...
PdYpsilon Posted June 21, 2008 Author Share Posted June 21, 2008 THANK YOU SO MUCH! Great! :-* Link to comment https://forums.phpfreaks.com/topic/111093-stristr-problem-with-reading-from-variable/#findComment-570691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.