SharkBait Posted September 19, 2006 Share Posted September 19, 2006 I have the following:[code]<?php$string = "TI-493";if(substr(strtolower($string), 0, 3) != "ti-") { echo "Error Wrong";} else { echo "Woo Right";}?>[/code]Am I doing this wrong with substr() should I be using something else? Quote Link to comment Share on other sites More sharing options...
SharkBait Posted September 20, 2006 Author Share Posted September 20, 2006 I still haven't figured this out... Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 20, 2006 Share Posted September 20, 2006 Works fine for me. I get "Woo Right". Is it not working for you? Could you explain what you are aiming to do. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted September 20, 2006 Author Share Posted September 20, 2006 I am looking to check the first 3 characters of a string a user inputs to see if they at least match. After the first 3 characters i dont care about Quote Link to comment Share on other sites More sharing options...
SharkBait Posted September 20, 2006 Author Share Posted September 20, 2006 This is the block of code that deals with a $_POST;[code]<?phpforeach($_POST['sn'] as $sn) { $sn = mysql_real_escape_string(trim($sn)); $pre = substr(strtolower($sn),0,3); if ($pre != "tr-") { echo "{$pre} <br />"; $errMsg .= "<li>The Serial Number must follow the TR- scheme.</li>"; break; } else { echo "AGHHFDF"; } if ($sn <> "") { $strqry = "SELECT * FROM rebates WHERE sn = '{$sn}'"; $query = mysql_query($strqry) or die("MySQL Error: Aborting Query"); $found = mysql_num_rows($query); if($found > 0) { $FOUNDSN[$b] = $sn; $SNFAILED = true; } else { $FOUNDSN[$b] = ""; } $i++; } else { $FOUNDSN[$b] = ""; } $b++; }?>[/code]Now it never echos the 'Pre is {$pre}' but it does assign [code=php:0] $errMsg .= "<li>The Serial.....</li>";[/code]It does echo the AGHHFDF so I am completely confused as to what is happening. Does it have to do with the break; I have? I want the foreach loop to stop on this if statement. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted September 20, 2006 Author Share Posted September 20, 2006 I used [code=php:0]echo gettype($sn);[/code] and it returned as a boolean type (which is what php.net says about substr()))So in the above code, am I really compairing a boolean to a string? Or am I right to think that its compairing a boolean to the integer value of "tr-" ?Am I comparing strings in an incorrect way??? Quote Link to comment Share on other sites More sharing options...
sasa Posted September 20, 2006 Share Posted September 20, 2006 can you print_r($_POST['sn']; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.