Log in

View Full Version : Joining two PHP strings together does not work



Ryan Fitton
01-19-2009, 11:11 PM
Hi, i am wanting to join two php strings together to form one string for my copyright bar, i have seen examples on the web most of these are:


$fragment1 = "The giraffe is ";

$fragment2 = "an interesting animal.";

$sentence1 = $fragment1 . $fragment2;


I have tried this with my code in which i tried:


$copyright_bottom="<a href='mailto:ryan.fitton@hotmail.co.uk'>Ryan Fitton</a>. All rights reserved. Copyright &copy; ". date("Y");

$copyright_bottom_valid=".<img src='images/spacer.gif' alt='' width='10' height='15' /><a href='http://validator.w3.org/check?uri=referer'>Valid XHTML</a> - <a href='http://jigsaw.w3.org/css-validator/check/referer'>Valid CSS</a> - <a href='http://www.php.net'>PHP</a>";

$copyright = $copyright_bottom . $copyright_bottom_valid;


But when i view the webpage my copyright bar is blank, if i just type the code in without it being in a string it shows up fine as like on my other web pages.

Site: http://rfitton.site50.net/index.php

Nile
01-19-2009, 11:19 PM
Once you do that you need to print or echo it:


$copyright_bottom="<a href='mailto:ryan.fitton@hotmail.co.uk'>Ryan Fitton</a>. All rights reserved. Copyright &copy; ". date("Y");

$copyright_bottom_valid=".<img src='images/spacer.gif' alt='' width='10' height='15' /><a href='http://validator.w3.org/check?uri=referer'>Valid XHTML</a> - <a href='http://jigsaw.w3.org/css-validator/check/referer'>Valid CSS</a> - <a href='http://www.php.net'>PHP</a>";

$copyright = $copyright_bottom . $copyright_bottom_valid;
echo $copyright;
//or:
print $copyright


You should use an array though:


<?php
$copyrights = array();
$copyrights[0] = "<a href='mailto:ryan.fitton@hotmail.co.uk'>Ryan Fitton</a>. All rights reserved. Copyright &copy; ".date('Y');
$copyrights[1] = "<img src='images/spacer.gif' alt='' width='10' height='15' /><a href='http://validator.w3.org/check?uri=referer'>Valid XHTML</a> - <a href='http://jigsaw.w3.org/css-validator/check/referer'>Valid CSS</a> - <a href='http://www.php.net'>PHP</a>";

echo implode($copyrights, ". ");
?>

I've also cleaned it a little bit.

Ryan Fitton
01-19-2009, 11:29 PM
Thanks very much nile i used the array, works like a dream :D

Nile
01-19-2009, 11:32 PM
Great! I'm glad to help you and your welcome Ryan. :)