473,385 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
Mar 24 '08 #1
1 2517
sh******@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\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
Mar 24 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lawrence | last post by:
Right now, over at www.monkeyclaus.org, the following script is getting to the 9th run through and dying after the line: echo "..."; You'll admit that is a strange place to die. I've hit...
2
by: Leif Wessman | last post by:
Hi, What am I doing wrong here? I want to display a transparent pixel... <? $transparent1x1 = array (71, 73, 70, 56, 57, 97, 1, 0, 1, 0, -128, 0, 0, 0, 0, 0, 0, 0, 0, 33, -7, 4, 1, 0, 0, 0,...
0
by: sjaak538 | last post by:
Hello I've a question about printing complex array's with print_r $xmlC->obj_data I get this example bellow But can anybody give me one example on how to echo $xmlC->obj_data; I try'd with...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
9
by: buda | last post by:
Hi, I've been wondering for a while now (and always forgot to ask :) what is the exact quote from the Standard that forbids the use of (&array) (when x >= number_of_columns) as stated in the FAQ...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
11
by: Twayne | last post by:
Hi, Irrelevant question time, probably: Is there any advantage/reason to use one format over the other for the following two types of echo statements? 1. echo "error is " . $error; 2. ...
3
tharden3
by: tharden3 | last post by:
Is there a quick way to ask to 'echo' or 'print' all elements of a numeric array? Can I specify to print "all of the keys" or "all of the values"? I wrote up 5 quick lines of code to print all of my...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.