niwa3836 Posted January 29, 2008 Share Posted January 29, 2008 Hi sorry silly question, bit stuck on Basically I am writing some code to reformat a string that comes in with lots of spaces. I have to be a little clever in my program as some of the column headers dont quite match with the content below (sometimes out by 1 char). The question is basically however: - Lets say $String = "This is a test" ; and i then do $out = "" ; $out[0] = $String[0] ; $out[1] = $String[1] ; $out[2] = $String[2] ; $out[3] = $String[3] ; If I: - print("Output " . $out) ; it says Array, but I want it to print "This" I know this is something silly but dont want to use print_r etc, is there a way of change $out array back to a normal string Comments please! Link to comment https://forums.phpfreaks.com/topic/88404-basic-question-on-arrays-strings/ Share on other sites More sharing options...
trq Posted January 29, 2008 Share Posted January 29, 2008 is there a way of change $out array back to a normal string I fail to see the point but.... <?php $String = "This is a test"; $out = array(); $out[0] = $String[0]; $out[1] = $String[1]; $out[2] = $String[2]; $out[3] = $String[3]; echo implode(' ', $out); ?> Link to comment https://forums.phpfreaks.com/topic/88404-basic-question-on-arrays-strings/#findComment-452457 Share on other sites More sharing options...
trq Posted January 29, 2008 Share Posted January 29, 2008 Just realised that would echo... T h i s You code for splitting the string into an array won't work as you expect. Maybe.... <?php $out = explode(' ', $String); ?> is what your after? Link to comment https://forums.phpfreaks.com/topic/88404-basic-question-on-arrays-strings/#findComment-452467 Share on other sites More sharing options...
sasa Posted January 29, 2008 Share Posted January 29, 2008 $String = "This is a test" ; $out = "" ; $out .= $String[0] ; $out .= $String[1] ; $out .= $String[2] ; $out .= $String[3] ; echo $out; Link to comment https://forums.phpfreaks.com/topic/88404-basic-question-on-arrays-strings/#findComment-452498 Share on other sites More sharing options...
resago Posted January 29, 2008 Share Posted January 29, 2008 whats the point? Link to comment https://forums.phpfreaks.com/topic/88404-basic-question-on-arrays-strings/#findComment-452934 Share on other sites More sharing options...
laffin Posted January 30, 2008 Share Posted January 30, 2008 looks like he trying to get the words, seperated which $words=explode(' ',$string); wid work thus echo $word[0] wud print out 'this' Link to comment https://forums.phpfreaks.com/topic/88404-basic-question-on-arrays-strings/#findComment-453006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.