asmith Posted December 4, 2007 Share Posted December 4, 2007 is there a function for deleteing one or more characters from the end of a string ? assuming don't knowing the length of the string . thanks Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 4, 2007 Share Posted December 4, 2007 strlen always knows the length of any string... <?php $string = 'somereallylongdrawnoutstring'; $string = substr($string, 0, strlen($string)-2); echo $string; PhREEEk Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 4, 2007 Share Posted December 4, 2007 Yes <?php $strString = "what is your name"; $strString = substr($strString,0,-1); echo $strString; ?> you can substitude the -1 to the amount of characters you want to delete Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 4, 2007 Share Posted December 4, 2007 strlen always knows the length of any string... PhREEEk I do not know how this would help ? if you read the question properly Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 4, 2007 Share Posted December 4, 2007 >assuming don't knowing the length of the string I read just fine Rajiv. I do appreciate your apparent concern. PhREEEk Quote Link to comment Share on other sites More sharing options...
asmith Posted December 4, 2007 Author Share Posted December 4, 2007 thanks guys ! Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 4, 2007 Share Posted December 4, 2007 Well PhREEEk you read and edit your post also fine... must I say. anyways no hard feelings Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 4, 2007 Share Posted December 4, 2007 Well PhREEEk you read and edit your post also fine... must I say. anyways no hard feelings Actually, I was in the middle of editing an example of strlen() when you jumped me. I read a little more into his question than you did. Whether he meant it or not, he implied that you need to know the length of a given string up front before you can perform an operation on it. My example used strlen() purposefully to show him how that function works. My aim is to educate wherever possible as priority one, giving a code snippet as priority two. Thanks again for your concern. PhREEEk Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 4, 2007 Share Posted December 4, 2007 I understand therefore I mentioned "No hard feelings"... it was just a comment I am sorry if it has offended you. 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.