8

When I try and echo this string it shows "0"

I tried it on my local server and on http://writecodeonline.com/php/ both times same thing happened. This has never happened to me before, what is it and how do I fix? Thanks in advance.

<?PHP
$info = '
                <div id="gallery_option_###number###">
                    <a href="#galleryButton###number###" onclick="gallery_button_down(' + "'###number###'" + ')">
                        Burn Notice
                    </a>
                    <div id="info_option_###number###">
                        <!--
                        [title]title[|title]
                        [description]test[|description]
                        [image]url[|image]
                        -->
                    </div>
                </div>';
                echo $info;
?>
2
  • 8
    Concatenation is "a" . "b", not "a" + "b". Commented Sep 4, 2011 at 3:49
  • Thanks, I am swapping between JS and PHP and missed it, it was driving me crazy! Commented Sep 4, 2011 at 3:50

1 Answer 1

16

You are following JavaScript way of string concatenation.

Read:

http://php.net/manual/en/language.operators.string.php

<?php
$a = "Hello ";
$b = $a . "World!"; // now $b contains "Hello World!"

$a = "Hello ";
$a .= "World!";     // now $a contains "Hello World!"
?>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.