Jump to content


This topic is now archived and is closed to further replies.


Can You Concatenate String Using += In Php 4.3.2?

Recommended Posts

Hey everyone, I'm trying to do something like this in PHP 4.3.2:
$string = "This is\tan example\nstring";

$tok = strtok($string, " \n\t");

$output = "<html><table><tr>";

while ($tok != false)
   $output += "<td>" . $tok . "</td>";
   $tok = strtok(" \n\t");
$output += $output . "</tr></table></html>";
echo $output;

But instead of getting a formated table with "This is an example string", i get a 0. I tried something simple like

[code]$output = "hi ";
$output += "there";[/code]

expecting to get "hi there" as the result but instead, i got a 0. I'm forced to do $output = $ouput . "some string..". The thing is that I know I've used the += to concatenate strings together, but I was using PHP 5. Is this something that's not available in PHP 4? Thanks!

Share this post

Link to post
Share on other sites
The concatenation operator in PHP is ".", not "+"

$a = "Hello"
$a .= " World";

echo $a; // Hello World

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.