ERuiz Posted October 11, 2007 Share Posted October 11, 2007 I have a script which receives _POST data from a program. I need to make sure that any data that has 747 in it, will be given a value I determine. I was thinking about something along these lines: $aircraft = $_POST[aircraft]; if ($aircraft == "%747%") { $aircraft = "B747"; } Would that work? I was thinking along the lines of the mySql LIKE commands where a % would be a wildcard. In other words, I want to check the variable $aircraft and if this variable has any reference to "747" (ej. Boeing747 or B747-200, et etc), then it will simply make it "B747". Thanks for any help... ERuiz Link to comment https://forums.phpfreaks.com/topic/72867-wildcard/ Share on other sites More sharing options...
Gafaddict Posted October 11, 2007 Share Posted October 11, 2007 You actually use a function for this: $aircraft = $_POST[aircraft]; $similar = strpos($aircraft, '747'); if($similar || $aircraft == "747") { $aircraft = "B747"; } In strpos, the first argument is the variable to search in and the second is what to search for. It returns a true if it could find it, a false if it couldn't. Link to comment https://forums.phpfreaks.com/topic/72867-wildcard/#findComment-367502 Share on other sites More sharing options...
Barand Posted October 12, 2007 Share Posted October 12, 2007 Wrong function! <?php $aircraft = '400'; $similar = strpbrk($aircraft, '747'); if($similar) { $aircraft = "B747"; } echo $aircraft; // B747 ?> Anything with a "7" or a "4" in it will return true . http://www.php.net/strpbrk Use http://www.php.net/strpos Link to comment https://forums.phpfreaks.com/topic/72867-wildcard/#findComment-367510 Share on other sites More sharing options...
ERuiz Posted October 12, 2007 Author Share Posted October 12, 2007 THANKS A MILLION! Hey wait, I now see that someone else replied! hahahah Which one of the 2 codes provided is the correct one? Link to comment https://forums.phpfreaks.com/topic/72867-wildcard/#findComment-367513 Share on other sites More sharing options...
teng84 Posted October 12, 2007 Share Posted October 12, 2007 maybe $string = 'sdfsdfsdXYZfsdf'; if (eregi('XYZ', $string)) { echo "'$string' contains a XYZ'!"; } Link to comment https://forums.phpfreaks.com/topic/72867-wildcard/#findComment-367516 Share on other sites More sharing options...
ERuiz Posted October 12, 2007 Author Share Posted October 12, 2007 LOL You guys are AWESOME!! Now which one of the 3 codes should I use? hahaahah This is great. :-) Link to comment https://forums.phpfreaks.com/topic/72867-wildcard/#findComment-367518 Share on other sites More sharing options...
Barand Posted October 12, 2007 Share Posted October 12, 2007 regex functions tend to be a lot slower. Use only when necessary. Link to comment https://forums.phpfreaks.com/topic/72867-wildcard/#findComment-367520 Share on other sites More sharing options...
teng84 Posted October 12, 2007 Share Posted October 12, 2007 yah i know thats why i say maybe but in somecase who knows we dont now if he needs regex for pattern Link to comment https://forums.phpfreaks.com/topic/72867-wildcard/#findComment-367522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.