BrainMeta'   Connectomics'  

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> PHP Pearls
Shawn
post Feb 15, 2004, 12:22 PM
Post #1


God
******

Group: Admin
Posts: 1498
Joined: Jan 22, 2003
From: CA
Member No.: 9



a thought a thread containing useful PHP code bits would be useful.

I'll start out with a useful way to assign strings using the heredoc syntax:

$text=<<<EOF
<html>
blah blah blah
$someVar
blah blah blah
</html>
EOF;


You can also echo heredoc strings this way too.

To view arrays, use print_r($array). Including <pre> tags is good for viewing large arrays; i.e.,

echo '<pre>'; print_r($your_array); echo '</pre>';


User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Shawn
post Feb 15, 2004, 12:42 PM
Post #2


God
******

Group: Admin
Posts: 1498
Joined: Jan 22, 2003
From: CA
Member No.: 9



This is a way to create a menu bar like the one above (i.e., Mind-Brain.com Forum -> Information Technology -> Web Programming -> PHP Pearls), and which I've now added to the top (on the left) of non-Forum pages.


//
// $excArray should contain all files that should NOT be
// included in your bookmarks.
// Ex. index.php, success.php etc etc
//
$excArray=array(
'index.php',
'index.html',
'listing.php',
);

if(!$path) {
$dirs=explode('/',$_SERVER['PHP_SELF']);
} else {
$urlArray=parse_url($path);
$dirs=explode('/',$urlArray['path']);
}
//
// Home Page
// Change the title and link text to suit
//
$op.="<a href=\"/\">Home</a> &gt; ";
foreach($dirs as $key => $val) {

//
// the numeric bit here can be removed if you do not have numeric
// directories (I use them instead of dynamic urls)
//
if($val!= "" &&!in_array($val,$excArray)) {
if ($oldval){
$op.=" &gt; <a href=\"/$oldval$val/\">$val</a>";
$oldval.="$val/";
}else{
$op.="<a href=\"/$val/\">$val</a>";
$oldval="$val/";
}


}
}
print "$op";


User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Shawn
post Feb 15, 2004, 12:53 PM
Post #3


God
******

Group: Admin
Posts: 1498
Joined: Jan 22, 2003
From: CA
Member No.: 9




Here's a PHP Countdown script:

the $bday variable contains the date to countdown to.
at the moment it is set to (23, 59, 0, 4, 17, 2003)
(which is 11:59pm, 17 April, 2003)

numbers are:
HOUR (24 hr), MINUTE, SECOND, MONTH, DAY, YEAR

SO, for example, you wanted to countdown to new year
2006, it would be
$bday = mktime(0, 0, 0, 1, 1, 2006);


<?
// change this for your date to countdown to
$bday = mktime(23, 59, 0, 4, 17, 2003);



print "Your countdown date is " . date("j F Y, g.i a", $bday) . ".<BR>";


print "You visited this page at " . date("j F Y, G.i:s", time());



$diff = $bday - time();


$days = ($diff - ($diff % 86400)) / 86400;
$diff = $diff - ($days * 86400);
$hours = ($diff - ($diff % 3600)) / 3600;
$diff = $diff - ($hours * 3600);
$minutes = ($diff - ($diff % 60)) / 60;
$diff = $diff - ($minutes * 60);
$seconds = ($diff - ($diff % 1)) / 1;


print "Only $days days, $hours hours, $minutes minutes and $seconds seconds until your countdown date!";
?>


User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 24th November 2017 - 12:38 PM


Home     |     About     |    Research     |    Forum     |    Feedback  


Copyright BrainMeta. All rights reserved.
Terms of Use  |  Last Modified Tue Jan 17 2006 12:39 am

Consciousness Expansion · Brain Mapping · Neural Circuits · Connectomics  ·  Neuroscience Forum  ·  Brain Maps Blog
 · Connectomics · Connectomics  ·  shawn mikula  ·  shawn mikula  ·  articles