/    Sign up×
Community /Pin to ProfileBookmark

Reading file into a foreach loop.

Having some trouble, and not sure where my prob is. This function SHOULD read the contents of a file (five sections named $cipher) include them one at a time, decrypt them, then echo them out in a div (class+1). If the file does not exist, it should die quietly. This was just a quick type-out so I’m not sure what errors are in it.

[code=php]
<?php
function tpout() {

GLOBAL $noko, $sct, $path;
$spec = array (
0 => ‘Specifications’, 1 => ‘Information’,
2 => ‘Maintenance’, 3 => ‘Safety’,
4 => ‘Troubleshooting’, ); # Declare TAPS

# Javascript to Run Show/Hide DIV’s
echo ‘<script type=”text/javascript”>’
echo ‘function tapper() {
el=document.getElementsByTagName(“div”)
for(var i=0;i<el.length;i++){
if(el[i].className==”tap”) {

if(el[i].style.display==”none”||el[i].style.display==””) {
el[i].style.display=”block”
} else {
el[i].style.display=”none”
} }
}
}’;
echo ‘</script>’;

# Style Configurator
echo ‘<style> .tap{ display:none; } </style>’;
echo ‘<div id=”tb”>’;

$i = 0; $name = $noko[1]; # Zeroing Out Increments

# Check if we really have a file to work with
$filename = $_SERVER[‘DOCUMENT_ROOT’] . “/$sct/$path/$name.php”;
if (file_exists($filename)) { include ($filename);
foreach ( $cipher AS $string ) {

# Name out Array Contents
echo “<div class=”tab”><a href=”#”>$spec[$i]</a>”;
echo “<div class=’tap$i’ style=”display:none”>”;

$hash = decrypt($s); stripslashes($hash); $i++;

echo $hash.”</div>”; # Push Decrypted Data
}

echo ‘</div>’;
$i = NULL; # Destroy Increments

} else { /* Die without Error */ }
?>
[/code]

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@jimr451Sep 01.2009 — Did you run this? What is it doing? That would help us narrow down what might be wrong.
Copy linkTweet thisAlerts:
@ehimeauthorSep 01.2009 — Edit Unexpect $end
[code=php]
<?php
function tpout() {

GLOBAL $noko, $sct, $path;
$spec = array (
0 => 'Specifications', 1 => 'Information',
2 => 'Maintenance', 3 => 'Safety',
4 => 'Troubleshooting', ); # Declare TAPS

# Javascript to Run Show/Hide DIV's
echo '<script type="text/javascript">';
echo 'function tapper() {
el=document.getElementsByTagName("div")
for(var i=0;i<el.length;i++){
if(el[i].className=="tap") {

if(el[i].style.display=="none"||el[i].style.display=="") {
el[i].style.display="block"
} else {
el[i].style.display="none"
} }
}
}';
echo '</script>';

# Style Configurator
echo '<style> .tap{ display:none; } </style>';
echo '<div id="tb">';

$i = 0; $name = $noko[1]; # Zeroing Out Increments

# Check if we really have a file to work with
$filename = $_SERVER['DOCUMENT_ROOT'] . "/$sct/$path/$name.php";
if (file_exists($filename)) { include ($filename);
foreach ( $cipher AS $s ) {

# Name out Array Contents
echo "<div class="tab"><a href="#">$spec[$i]</a>";
echo "<div class='tap$i' style="display:none">";

$hash = decrypt($s);
echo stripslashes($hash);

echo "</div>"; $i++; # Push Decrypted Data
}

echo '</div>';
$i = NULL; # Destroy Increments

} else { /* Die without Error */ }

?>
[/code]
Copy linkTweet thisAlerts:
@ehimeauthorSep 01.2009 — I fixed the gross errors and it looks like its locking up at my foreach loop.
Copy linkTweet thisAlerts:
@ehimeauthorSep 01.2009 — if I include crypto here (and no where else) it tells me that I am trying to redeclare encrypt(), if I don't include it, it tell me that I have an invalid argument in my foreach loop?

the ciphers look like this:[code=php]
$cipher = # Cipher Block / Specifications
'M0zOgi0aHMSIrHNXJd7S1HsBWZM6uPtyXeASqLxXiC+g+w8qrcZtmvZNdabWl5/rC8dxw8Cj2zx83oFHi/a11'.
'DYjDToECEuT8fU16bek9s69vJng9DhXHdMyYcMJH90JIVUgxpnTy1VY54oZ2xi0x2JCgefONN5ZpdCqLOfRP/'.
'fJfK8QbKq0CcuZuy6DBh6g1/vrHd59XLaPX1mXpNkjgtsy5JXCbKkfPIvmYlTveEVDHeyaeLDDwHUl/OHdQ5E'.
'EOFq/1I15PdqarMdd2/l2bZN5DUkWo78TxAhkb2/dcDW4NFNgbYJgrqMKFieGddBsy/5Fv3VPfSaexVdZDWig'.
'8kiduG1B6be07WD/BicxFvISQnbdlJ1cWO5Aj8OvSzI3sIM3/aJ9VAYPFugDov13ifCdH+rkY6Ayq45OUXeq7'.
'Hwp2AOWJxxZINbAc33tROn5hhZOiBsmne9SpV2AzGjiUbA2Mb1//ZMPL7ki5zFZjjlbu0PhgzDFg6zAsNIPQz';

$cipher = # Cipher Block / Information
'fa8VIai59HXBnO1/x0ofsIC5hxpH0/0n63vonGhOyaHz+SprZHc29+qR7jDlA/0qGaDZgpJCzVD4xiQ0VcpiS'.
'vbPjQp/rjYIFiUTWlBvVzXZqq8a5fxD4mRj6+hihpKff+gI2OKlCippjuB96J8GZkC8p69kQTm9l69dc3HW3q'.
'CYCn50+w2O/ocAPWLa+JOblWGiYhYu0fe7wCRFGUO3ynByxDhWV4XjpappW83PPyE9J9Y3JEwjhr9Zc+lut1v';

$cipher = # Cipher Block / Maintenance
'fa8VIai59HXBnO1/x0ofsIC5hxpH0/0n63vonGhOyaFIFdZvWqX05FqzvGgQgpWIaAesTan2M6nSTt8PZjAGV'.
'eO2ErcEWjPlAW48GauWrZpiSQllabGOMvM3vkbqIiIYP6OSFT4iWzHiwez/TusSPmqsF8pBxgk3xx5MUZvROu'.
't9PcQQtC+nufxHpo3++06pmhsxeVVV3XL87oltVAAV0ryMgBkc1aADA1sIZUAbppQ0La038Jr1yqGRjay1MLN';

$cipher = # Cipher Block / Safety
'fa8VIai59HXBnO1/x0ofsIC5hxpH0/0n63vonGhOyaFlP4D1qReZINHU4z+HDOblh9kVqSfPL6Xle8MdJrUck'.
'Bnz9Kb4sWrmn5gLwL5nrE+mov7fUO3DfzENTmhasfC7Lx9TtuS41nddY8hcWL3Tm8gh2gFgcWvCXOQfajPOIG'.
'4w1nyAkkzudvojR637KkEyjQOyhHSS13chDBSdzGMoDaG+uzYTTL8gSa9ZbWTTyF84ayr7h7+gBOCjGwN61F3';

.etc[/code]
Copy linkTweet thisAlerts:
@criterion9Sep 01.2009 — Do you have a closing brace for the function? It doesn't seem to be included in the first post.
Copy linkTweet thisAlerts:
@ehimeauthorSep 01.2009 — I saw that, and inserted it, yes.
Copy linkTweet thisAlerts:
@criterion9Sep 01.2009 — $cipher is not an array the way it displayed above. You are reassigning the value with each addition. If you want it to be an array use one of the array assignments such as:
[code=php]
$cipher[] = "blah blah";
[/code]
Copy linkTweet thisAlerts:
@ehimeauthorSep 01.2009 — Does cipher need to be an array though? I thought I could use it as a string?
Copy linkTweet thisAlerts:
@criterion9Sep 01.2009 — foreach is used to loop through each instance in an array. Additionally, if you have a file that resets the variable repeatedly you will only be able to access the value you set it to last.

Example:

[code=php]
$var1 = "a";
$var1 = "b";
$var1 = "c";

echo $var1;
[/code]

Will output:
<i>
</i>c


Check out the manual on Arrays.
Copy linkTweet thisAlerts:
@ehimeauthorSep 01.2009 — So it seems like it's close to working. You can see here what I mean.

[url=http://omnisistem.com/layers/lighting/prl-test.php]Click Here[/url] Then the Century Color, it's still doing weird stuff...
Copy linkTweet thisAlerts:
@criterion9Sep 01.2009 — Um....ok. I didn't see any php errors or anything. What did that link have to do with the problem above?
Copy linkTweet thisAlerts:
@ehimeauthorSep 01.2009 — That's the link to the page I'm using it on.
Copy linkTweet thisAlerts:
@criterion9Sep 01.2009 — What do you mean by "its still doing weird stuff"?
Copy linkTweet thisAlerts:
@ehimeauthorSep 02.2009 — I think it (might be) the Javascript? On clicking other links it blanks out half of my background bar.
Copy linkTweet thisAlerts:
@criterion9Sep 02.2009 — My guess would be either css or javascript. Does it happen on all the tabs or just a selection of them?
Copy linkTweet thisAlerts:
@ehimeauthorSep 02.2009 — I believe you're right, it only happens on certain ones?
Copy linkTweet thisAlerts:
@ehimeauthorSep 02.2009 — I should have had it as a floating element.
×

Success!

Help @ehime spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...