bgsomers Posted January 15, 2007 Share Posted January 15, 2007 The code echo "buffer--|".$buffer."|--end<br/>";trim($buffer, " ");echo "trimmed buffer--|".$buffer."|--end<br/>";rtrim($buffer, " ");echo "rtrimmed buffer--|".$buffer."|--end<br/>";leads to the outputbuffer--|term1 10 |--endtrimmed buffer--|term1 10 |--endrtrimmed buffer--|term1 10 |--endThe descriptions of trim() and rtrim() do not suggest that they will leave a trailing space in the string processed.How should one understand this situation?Bruce(Sorry - I can't see what is limiting the length of the code lines above.) Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 15, 2007 Share Posted January 15, 2007 You are not changing the value of buffer! trim() returns a trimmed value, but you are not assigning it to anything or using it.You need to do this:[code]echo "buffer--|".$buffer."|--end";$buffer = trim($buffer, " ");echo "trimmed buffer--|".$buffer."|--end";$buffer = rtrim($buffer, " ");echo "rtrimmed buffer--|".$buffer."|--end";[/code]Or this:[code]echo "buffer--|".$buffer."|--end";echo "trimmed buffer--|".trim($buffer, " ")."|--end";echo "rtrimmed buffer--|".rtrim($buffer, " ")."|--end";[/code]Edit: Also, spaces are included in the "trimmed" character list be default. You don't need to include it in the function as the 2nd parameter. Quote Link to comment Share on other sites More sharing options...
bgsomers Posted January 16, 2007 Author Share Posted January 16, 2007 ---You are not changing the value of buffer! trim() returns a trimmed value, but you are not assigning it to anything or using it.Great Scott! Thank you very much.Bruce 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.