When playing around and helping some guys at work learn more PHP I thought I would keep a record of some things we discussed.
echo " 123"; will print out a capital "S" - the octec value for S is 123.
when posting files from a form, use <form action="foo.php" method="post" enctype="multipart/form-data"> without the enctype the file will not be sent to the server
when storing data in sessions: if there is a session key called $_SESSION['products'] and you use $products somewhere in your scripts for a different reason eg: $products=query("SELECT * FROM...); on some PHP configurations $products and $_SESSION['products'] will be the same, so be careful with session key names. you could end up inadvertently messing with session values
if you have an input element <input type="checkbox" name="foo[123]" value="Bar"> PHP will convert foo[123] into an array for you automatically. You can access this like: $foo = $_POST['foo']; echo $foo["123"]; // this prints Bar
after submitting a form (lets say a sign up form) it is always best to redirect the user to a separate "thank you" page instead of simply displaying a thankyou message at the end of the sign up script. this means if a user refreshes the "thank you" page, it will not sign them up again / throw a nasty re-post warning message in the browser.
more to come ...
PHP:
<?=($foo)?$bar:$moo;?>
same as:
<? if($foo) echo $bar; else echo $moo; ?>
<input type="checkbox" name="box[a]" value=yes>
<input type="checkbox" name="box[b]" value=yes>
<input type="checkbox" name="box[c]" value=yes>
<input type="checkbox" name="box[d]" value=yes>
print_r($_REQUEST);
json_encode()
while($v<20){
?> <tr bgcolor="<?=($v++%2)?'red':'green';?>"><td>fasdf</td></tr> <?
}preg_match("/^(http:\/\/info@)?([^\/]+)/i","http://info@abc.com", $data);
echo $data[2]; HTML:
whats a <th>
Javascript:
var moo = {
foo: function(){
var b = this.a--;
alert(--b)
},
a: 4
}
moo.a=3;
moo.foo();// alerts 2
var moo = {a : "string", b: 4, c: function(){ alert('moo'); } };
|
Collector Comics is THE place to buy, sell, and research comics online. Launching soon.
Launch »
Screenshot »
|
|
Webitor is a kick-ass easy to use, easy to extend, non-database driven Content Management System. Version 2 with reseller plan coming soon.
Launch »
Version 1 »
|
|
GC Lounge is my own pet social network and test bed for social related code. Made by locals for locals.
Launch »
|
|
GG has indexed over half a million recent Trade Mark applications. This revolutionary tool is extremely valuable for industry experts.
Launch »
|
|
GCWiFi is the hub for techies interested in joining a ad-hoc wireless mesh spread across the Gold Coast
Launch »
|
|
Web based financial client management system
Launch »
|
|
OS Commerce modules and template modification
Launch »
|
| View More Projects » | |