Re: [PHP] string concatenation from array
On Tue, Aug 12, 2003 at 01:58:21PM -0600, Micah Montoy wrote: I'm having a bit of difficulty getting a string to attach to itself from an array. Here is the bit of code I'm working on. A bunch of simplifications, efficiency tweaks on this approach... $wresult = ; $wresult = ''; foreach ($search_string as $word_result){ $wresult = $wresult $word_result; $wresult = $wresult . ' ' . $word_result; OR you can do... $wresult .= $word_result; } echo ($wresult); echo $wresult; BUT, the far far far better way to do this just takes one line: echo implode(' ', $search_string); --Dan -- FREE scripts that make web and database programming easier http://www.analysisandsolutions.com/software/ T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7th Ave #4AJ, Brooklyn NYv: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string concatenation from array
Micah, The sign in PHP (to the best of my knowledge) does not concatenate. Use a . instead. See below. $wresult = ; foreach ($search_string as $word_result){ $wresult .= $word_result; } That should work for you. Jonathan Pitcher On Tuesday, August 12, 2003, at 02:58 PM, Micah Montoy wrote: I'm having a bit of difficulty getting a string to attach to itself from an array. Here is the bit of code I'm working on. $wresult = ; foreach ($search_string as $word_result){ $wresult = $wresult $word_result; } echo ($wresult); Anyone see why when I run through each part of the array, it won't attach the next string and so on? thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] string concatenation from array
Analysis Solutions mailto:[EMAIL PROTECTED] on Tuesday, August 12, 2003 1:02 PM said: OR you can do... $wresult .= $word_result; Don't forget the space: $wresult .= .$word_result; c. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string concatenation from array
From: Jonathan Pitcher [EMAIL PROTECTED] The sign in PHP (to the best of my knowledge) does not concatenate. Correct, it's a bitwise AND operator. http://us2.php.net/manual/en/language.operators.bitwise.php ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string concatenation from array
Of course, in this case, it would be much easier replace all of the above with echo join(' ', $search_string); and be done with it. :-) -- Peter James Editor-in-Chief, php|architect Magazine [EMAIL PROTECTED] php|architect The Magazine for PHP Professionals http://www.phparch.com - Original Message - From: Peter James [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 2:18 PM Subject: Re: [PHP] string concatenation from array My personal favourite is to use an array. It's much cleaner syntax IMO...it is very easy to miss a '.' on a '.=', and introduce a nasty bug. $wresult = array(); foreach ($search_string as $word_result) { $wresult[] = $word_result; } echo join('', $wresult); or in php 4.3 echo join($wresult); -- Peter James Editor-in-Chief, php|architect Magazine [EMAIL PROTECTED] php|architect The Magazine for PHP Professionals http://www.phparch.com - Original Message - From: Matt Giddings [EMAIL PROTECTED] To: 'Micah Montoy' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 2:00 PM Subject: RE: [PHP] string concatenation from array Use the . concatenation operator. : ) $wresult = ; foreach ($search_string as $word_result) { $wresult = $wresult . . $word_result; } echo $wresult; Matt -Original Message- From: Micah Montoy [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 3:58 PM To: [EMAIL PROTECTED] Subject: [PHP] string concatenation from array I'm having a bit of difficulty getting a string to attach to itself from an array. Here is the bit of code I'm working on. $wresult = ; foreach ($search_string as $word_result){ $wresult = $wresult $word_result; } echo ($wresult); Anyone see why when I run through each part of the array, it won't attach the next string and so on? thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] string concatenation from array
Use the . concatenation operator. : ) $wresult = ; foreach ($search_string as $word_result) { $wresult = $wresult . . $word_result; } echo $wresult; Matt -Original Message- From: Micah Montoy [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 3:58 PM To: [EMAIL PROTECTED] Subject: [PHP] string concatenation from array I'm having a bit of difficulty getting a string to attach to itself from an array. Here is the bit of code I'm working on. $wresult = ; foreach ($search_string as $word_result){ $wresult = $wresult $word_result; } echo ($wresult); Anyone see why when I run through each part of the array, it won't attach the next string and so on? thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string concatenation from array
My personal favourite is to use an array. It's much cleaner syntax IMO...it is very easy to miss a '.' on a '.=', and introduce a nasty bug. $wresult = array(); foreach ($search_string as $word_result) { $wresult[] = $word_result; } echo join('', $wresult); or in php 4.3 echo join($wresult); -- Peter James Editor-in-Chief, php|architect Magazine [EMAIL PROTECTED] php|architect The Magazine for PHP Professionals http://www.phparch.com - Original Message - From: Matt Giddings [EMAIL PROTECTED] To: 'Micah Montoy' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 2:00 PM Subject: RE: [PHP] string concatenation from array Use the . concatenation operator. : ) $wresult = ; foreach ($search_string as $word_result) { $wresult = $wresult . . $word_result; } echo $wresult; Matt -Original Message- From: Micah Montoy [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 3:58 PM To: [EMAIL PROTECTED] Subject: [PHP] string concatenation from array I'm having a bit of difficulty getting a string to attach to itself from an array. Here is the bit of code I'm working on. $wresult = ; foreach ($search_string as $word_result){ $wresult = $wresult $word_result; } echo ($wresult); Anyone see why when I run through each part of the array, it won't attach the next string and so on? thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php