Results 1 to 4 of 4

Thread: Joining two PHP strings together does not work

  1. #1
    Join Date
    Feb 2007
    Posts
    145
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Joining two PHP strings together does not work

    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:
    PHP Code:
    $fragment1 "The giraffe is ";

    $fragment2 "an interesting animal.";

    $sentence1 $fragment1 $fragment2
    I have tried this with my code in which i tried:
    PHP Code:
    $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

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Once you do that you need to print or echo it:
    PHP Code:
    $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 Code:
    <?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.
    Last edited by Nile; 01-19-2009 at 11:22 PM. Reason: Fixed code.. -.-
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    Ryan Fitton (01-19-2009)

  4. #3
    Join Date
    Feb 2007
    Posts
    145
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks very much nile i used the array, works like a dream

  5. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Great! I'm glad to help you and your welcome Ryan.
    Jeremy | jfein.net

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •