SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Sep 2008
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Some Basic PHP Help

    I have an info.php file where I have things that will appear on alot of pages like my menu and one of the things I have in the file is


    Code php:
    <?php
    $text1 = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at sem at justo venenatis venenatis id at ipsum. Integer non cursus lectus. Aliquam adipiscing elit sit amet velit tristique aliquam.</p>"
    $name1 = "name1"
    ?>

    Say I wanted to place "<?php echo $name1 ?> inside the paragraph for $text1.. is that possible? how would I do it?

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You wouldn't put it as a PHP command as it won't get parsed inside a string.

    Instead you would concatenate it into the string, like so:
    PHP Code:
    <?php
    $name1 
    'name1';
    $text1 "<p>{$name1} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at sem at justo venenatis venenatis id at ipsum. Integer non cursus lectus. Aliquam adipiscing elit sit amet velit tristique aliquam.</p>";
    ?>
    or
    PHP Code:
    <?php
    $name1 
    'name1';
    $text1 '<p>' $name1 ' Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at sem at justo venenatis venenatis id at ipsum. Integer non cursus lectus. Aliquam adipiscing elit sit amet velit tristique aliquam.</p>';
    ?>
    or
    PHP Code:
    <?php
    $name1 
    'name1';
    $text1 SPrintF('<p>%s Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at sem at justo venenatis venenatis id at ipsum. Integer non cursus lectus. Aliquam adipiscing elit sit amet velit tristique aliquam.</p>'$name1);
    ?>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


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
  •