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! Quote 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); ?> Quote 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? Quote 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; Quote 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? Quote 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' Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.