paulman888888 Posted September 26, 2009 Share Posted September 26, 2009 Hi again; My Quick Question is; is there a easy way to check if the first to characters of a string is equal to a variable? Thankyou All Paul Quote Link to comment https://forums.phpfreaks.com/topic/175610-solved-quick-question-using-if/ Share on other sites More sharing options...
Daniel0 Posted September 26, 2009 Share Posted September 26, 2009 Yeah, you can use substr. Quote Link to comment https://forums.phpfreaks.com/topic/175610-solved-quick-question-using-if/#findComment-925352 Share on other sites More sharing options...
monkeytooth Posted September 26, 2009 Share Posted September 26, 2009 Not really a quick one, but yes methods do exist that can help you break down strings in a variety of ways including finding the first word and turning it into a var. Which then can be compared to other vars Quote Link to comment https://forums.phpfreaks.com/topic/175610-solved-quick-question-using-if/#findComment-925353 Share on other sites More sharing options...
MadTechie Posted September 26, 2009 Share Posted September 26, 2009 another option $string = 'Hello world'; $X = $string[0]; echo $X;//return H however i use substr() myself $string = 'Hello world'; $X = substr($string,0,1); echo $X;//return H EDIT: updated to set $X as the first letter (in case it helps) Quote Link to comment https://forums.phpfreaks.com/topic/175610-solved-quick-question-using-if/#findComment-925365 Share on other sites More sharing options...
paulman888888 Posted October 1, 2009 Author Share Posted October 1, 2009 Thanks guys! Also i never new that you could access a string useing array like functions! I dont think i said that in a cleaver way. Want i meant to say was; i never new you could use $string='something'; and access as $string[number]; Great help! Thanks Paul Quote Link to comment https://forums.phpfreaks.com/topic/175610-solved-quick-question-using-if/#findComment-928351 Share on other sites More sharing options...
Daniel0 Posted October 1, 2009 Share Posted October 1, 2009 That's because you haven't read the manual Quote Link to comment https://forums.phpfreaks.com/topic/175610-solved-quick-question-using-if/#findComment-928356 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.