Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 24th, 2008, 06:05 PM
sheel331@yahoo.com
Guest
 
Posts: n/a
Default 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\webroot\sheel\template\navbar.html';

$fullPath = explode('/', $_SERVER['PHP_SELF']);
echo "The foldername $fullPath[0]";
echo "The filename $fullPath[1]";
echo 'c:\inetpub\webroot\sheel\template\'.$($fullPath[1]).".html";

$filename = 'c:\inetpub\webroot\sheel\template\' .
$fullPath[1].'.html';
$filename2 = 'c:\inetpub\webroot\sheel\template\' .
$fullPath[1].'.html';

if (file_exists($fileName)) {
echo "c:\inetpub\webroot\sheel\template\$fullPath[1].html";
include 'c:\inetpub\webroot\sheel\template\'.
$fullPath[1].'.html';}
else if (file_exists($fileName2)) {
echo "c:\inetpub\webroot\sheel\template\$fullPath[2].html";
include 'c:\inetpub\webroot\sheel\template\'.
$fullPath[2].'.html';}
else{
echo "<ul id=\"secondaryNav\" ></ul>";}
?>

Thanks for your help!
Sheel
  #2  
Old March 24th, 2008, 08:05 PM
sheldonlg
Guest
 
Posts: n/a
Default Re: Echo array elements

sheel331@yahoo.com wrote:
Quote:
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\webroot\sheel\template\navbar.html';
>
$fullPath = explode('/', $_SERVER['PHP_SELF']);
echo "The foldername $fullPath[0]";
echo "The filename $fullPath[1]";
echo 'c:\inetpub\webroot\sheel\template\'.$($fullPath[1]).".html";
>
$filename = 'c:\inetpub\webroot\sheel\template\' .
$fullPath[1].'.html';
$filename2 = 'c:\inetpub\webroot\sheel\template\' .
$fullPath[1].'.html';
>
if (file_exists($fileName)) {
echo "c:\inetpub\webroot\sheel\template\$fullPath[1].html";
include 'c:\inetpub\webroot\sheel\template\'.
$fullPath[1].'.html';}
else if (file_exists($fileName2)) {
echo "c:\inetpub\webroot\sheel\template\$fullPath[2].html";
include 'c:\inetpub\webroot\sheel\template\'.
$fullPath[2].'.html';}
else{
echo "<ul id=\"secondaryNav\" ></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\webroot\sheel\template\$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\\webroot\\sheel\\template\\" . $fullPath[1] . ".html";

since the backslash is a quoting character.

Shelly
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles