spires Posted May 30, 2009 Share Posted May 30, 2009 Hi. I'm trying to work out how I check to see if my number is a negative. Example. $str = '-450'; So basically, I want to check if string $str contains a - Any ideas would be great, thanks. Link to comment https://forums.phpfreaks.com/topic/160263-solved-quick-string-question/ Share on other sites More sharing options...
Michdd Posted May 30, 2009 Share Posted May 30, 2009 Couldn't you just do: if($str < 0) { //whatever } Link to comment https://forums.phpfreaks.com/topic/160263-solved-quick-string-question/#findComment-845756 Share on other sites More sharing options...
Garethp Posted May 30, 2009 Share Posted May 30, 2009 http://www.maxi-pedia.com/string+contains+substring+PHP Link to comment https://forums.phpfreaks.com/topic/160263-solved-quick-string-question/#findComment-845757 Share on other sites More sharing options...
spires Posted May 30, 2009 Author Share Posted May 30, 2009 Perfect, Thanks Link to comment https://forums.phpfreaks.com/topic/160263-solved-quick-string-question/#findComment-845758 Share on other sites More sharing options...
Michdd Posted May 30, 2009 Share Posted May 30, 2009 If you insist in searching the string for a '-' you can do: $check = strpos($str, '-'); if($check === false) { echo "It is a positive"; } else { echo "It is negative"; } Link to comment https://forums.phpfreaks.com/topic/160263-solved-quick-string-question/#findComment-845759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.