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.) Link to comment https://forums.phpfreaks.com/topic/34272-trim-and-rtrim/ 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. Link to comment https://forums.phpfreaks.com/topic/34272-trim-and-rtrim/#findComment-161186 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 Link to comment https://forums.phpfreaks.com/topic/34272-trim-and-rtrim/#findComment-162418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.