Echo array elements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sheel331@yahoo.com

    Echo array elements

    Hello, I am new to coding in PHP, and had a question about a simple
    thing:

    I am trying to echo out the elements of an array for a sidenav in one
    of my HTML pages, and I can't seem to figure out the syntax for
    appending the element of the array into the path to the file. Here is
    the code I have:

    <?php
    include 'c:\inetpub\web root\sheel\temp late\navbar.htm l';

    $fullPath = explode('/', $_SERVER['PHP_SELF']);
    echo "The foldername $fullPath[0]";
    echo "The filename $fullPath[1]";
    echo 'c:\inetpub\web root\sheel\temp late\'.$($fullP ath[1]).".html";

    $filename = 'c:\inetpub\web root\sheel\temp late\' .
    $fullPath[1].'.html';
    $filename2 = 'c:\inetpub\web root\sheel\temp late\' .
    $fullPath[1].'.html';

    if (file_exists($f ileName)) {
    echo "c:\inetpub\web root\sheel\temp late\$fullPath[1].html";
    include 'c:\inetpub\web root\sheel\temp late\'.
    $fullPath[1].'.html';}
    else if (file_exists($f ileName2)) {
    echo "c:\inetpub\web root\sheel\temp late\$fullPath[2].html";
    include 'c:\inetpub\web root\sheel\temp late\'.
    $fullPath[2].'.html';}
    else{
    echo "<ul id=\"secondaryN av\" ></ul>";}
    ?>

    Thanks for your help!
    Sheel
  • sheldonlg

    #2
    Re: Echo array elements

    sheel331@yahoo. com wrote:
    Hello, I am new to coding in PHP, and had a question about a simple
    thing:
    >
    I am trying to echo out the elements of an array for a sidenav in one
    of my HTML pages, and I can't seem to figure out the syntax for
    appending the element of the array into the path to the file. Here is
    the code I have:
    >
    <?php
    include 'c:\inetpub\web root\sheel\temp late\navbar.htm l';
    >
    $fullPath = explode('/', $_SERVER['PHP_SELF']);
    echo "The foldername $fullPath[0]";
    echo "The filename $fullPath[1]";
    echo 'c:\inetpub\web root\sheel\temp late\'.$($fullP ath[1]).".html";
    >
    $filename = 'c:\inetpub\web root\sheel\temp late\' .
    $fullPath[1].'.html';
    $filename2 = 'c:\inetpub\web root\sheel\temp late\' .
    $fullPath[1].'.html';
    >
    if (file_exists($f ileName)) {
    echo "c:\inetpub\web root\sheel\temp late\$fullPath[1].html";
    include 'c:\inetpub\web root\sheel\temp late\'.
    $fullPath[1].'.html';}
    else if (file_exists($f ileName2)) {
    echo "c:\inetpub\web root\sheel\temp late\$fullPath[2].html";
    include 'c:\inetpub\web root\sheel\temp late\'.
    $fullPath[2].'.html';}
    else{
    echo "<ul id=\"secondaryN av\" ></ul>";}
    ?>
    >
    Thanks for your help!
    Sheel

    I have not followed your code, but I noticed one thing that I do
    differently. I would always write this line:

    echo "c:\inetpub\web root\sheel\temp late\$fullPath[1].html";

    as

    echo "c:/inetpub/webroot/sheel/template/" . $fullPath[1] . ".html";
    or

    echo 'c:/inetpub/webroot/sheel/template/' . $fullPath[1] . '.html';

    That is, I would separate the string from the variable explicitly and I
    would use unix notation. Otherwise (I'm not 100% certain), you may well
    need

    echo "c:\\inetpub\\w ebroot\\sheel\\ template\\" . $fullPath[1] . ".html";

    since the backslash is a quoting character.

    Shelly

    Comment

    Working...