brem13 Posted April 16, 2010 Share Posted April 16, 2010 how would i check for a space in a string? if(str($values['username) == " ") doesnt work and I didnt think it would Link to comment https://forums.phpfreaks.com/topic/198755-check-for-space-in-string/ Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 Read strpos if (strpos($values['username'], " ") !== false) Link to comment https://forums.phpfreaks.com/topic/198755-check-for-space-in-string/#findComment-1043103 Share on other sites More sharing options...
ChemicalBliss Posted April 16, 2010 Share Posted April 16, 2010 Another Way if( false !== preg_match("/[ ]+/i",$some_string)){ // It has space!! } Preg Match is very powerful and robust. -cb- Link to comment https://forums.phpfreaks.com/topic/198755-check-for-space-in-string/#findComment-1043104 Share on other sites More sharing options...
brem13 Posted April 16, 2010 Author Share Posted April 16, 2010 thank you both! Link to comment https://forums.phpfreaks.com/topic/198755-check-for-space-in-string/#findComment-1043105 Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 1. preg_match returns an int unless there's an error, which I doubt. 2. You don't need the [ and ] in the regexp. 3. preg_match uses regular expression which is more extensive than a simple string match. Though it's just a space. Link to comment https://forums.phpfreaks.com/topic/198755-check-for-space-in-string/#findComment-1043107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.