Jump to content


Photo

Can You Concatenate String Using += In Php 4.3.2?


  • Please log in to reply
2 replies to this topic

#1 colinexl

colinexl
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 27 June 2006 - 09:27 PM

Hey everyone, I'm trying to do something like this in PHP 4.3.2:
<?php
$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

$output = "hi ";
$output += "there";

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!

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 27 June 2006 - 09:37 PM

The concatenation operator in PHP is ".", not "+"

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

echo $a; // Hello World
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 colinexl

colinexl
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 27 June 2006 - 09:46 PM

oh yahh.. that's right, thanks lol stupid me




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users