Vault9 Modding Vault9 Graphics Vault9 Code Vault9 Net Vault9 OS Vault9 Gaming Vault9 ChillZone Vault9 Tech Vault9 Archives       Vault9 Global9       Vault9 Fusion     Vault9 Blog     Vault9 Network          
 

Please Note!

This is a read-only board, no new topics or registrations are allowed. The Code Vault has moved to http://forums.vault9.net - Be sure to find more information there!


 
Reply to this topicStart new topic
> Tips N Tricks, Add anything of value
post Jun 18 2004, 03:20 AM
Post #1


wild bastard
Group Icon

Group: Administration
Posts: 5,168
Joined: 4-June 02
From: Johannesburg South Africa
Member No.: 1

Sex: Male



Post anything that could be of value to other coders.

Heres a start

CODE

<%
<?
<?php


are all usable tags but the most generally accepted and prefered tag is
CODE

<?php


So to prevent any bad habits , start using the correct tags now and prevent yourself from using the other tags by editting php.ini and turn short tags off and turn asp style tags off.

Other coders will appreciate this.


--------------------
User is offlineProfile CardPM
+Quote PostGo to the top of the page
post Jun 18 2004, 03:20 AM
Post #


Member


Group: Administration

Joined: Today, 05:55 PM





Quote PostGo to the top of the page
post Jun 18 2004, 04:31 AM
Post #2


bovine satisfaction
Group Icon

Group: Administration
Posts: 1,748
Joined: 27-April 02
From: In teh pastures
Member No.: 162

Sex: Male



variable tips by o-juice and Relic Viper.

QUOTE(o-juice)
if (!empty($_GET)) {
extract($_GET);
} else if (!empty($HTTP_GET_VARS)) {
extract($HTTP_GET_VARS);
}
if (!empty($_POST)) {
extract($_POST);
} else if (!empty($HTTP_POST_VARS)) {
extract($HTTP_POST_VARS);
}


QUOTE(Relic Viper)
  if(phpversion() >= "4.2.1") {
     extract($_POST);
     extract($_GET);
     extract($_SERVER);
     extract($_SESSION);
     extract($_COOKIE);
     extract($_FILES);
     extract($_ENV);
     extract($_REQUEST);
     if ($_GLOBALS !=""){
        extract($_GLOBALS);
     }
  }


These two snippets will solve problems brought about by coding with register globas on, and moving into an environment where it is off.


--------------------
User is offlineProfile CardPM
+Quote PostGo to the top of the page
post Jun 18 2004, 04:56 AM
Post #3


Lilium Inter Spinas
Group Icon

Group: Administration
Posts: 788
Joined: 24-June 02
From: Johannesburg, ZA
Member No.: 383

Sex: Male



Snippet from the latest Mars&Venus code - just something I wrote to neatly return a nice display from a SQL TIMESTAMP

CODE
function sqltime($timestamp){ //quick fx badc0de to ease up sql time
  return( substr($timestamp, 8, 2) . ':' . substr($timestamp, 10, 2) . ' ' .
       substr($timestamp, 6, 2) . '/' . substr($timestamp, 4, 2) . '/' . substr($timestamp, 2, 2) );
}


call it like so - $nicetime=sqltime($messytime);


--------------------
User is offlineProfile CardPM
+Quote PostGo to the top of the page
post Aug 19 2004, 10:43 AM
Post #4


:o 'o' o:
Group Icon

Group: Regular Member
Posts: 270
Joined: 11-August 02
Member No.: 530




Magic quotes gpc, automatically adds " 's to strings, thats why with some sites... any "'s, have \'s or something... its bugging

Just remember, if you do disable it... any strings you send to a database MUST have slashes
So: 'SELECT * FROM '.$table.' WHERE x=4'
Should become: 'SELECT * FROM '.addslashes($table).' WHERE x = 4'

Anyway, the removal script
(Only runs when it is activated)
CODE

/*----------------------------------------------
           MAGIC QUOTES DISABLER
 
hopefully this file is included before
          anything else
----------------------------------------------*/
// ah... before we do anything, kill teh magic_quotes -- YAY
function StripSlashArray_Deep(&$array)
{
foreach ($array as $key=>$value)
{
 if (is_array($value))
 {
  StripSlashArray_Deep($array[$key]);
 }else if (is_string($value))
 {
  $array[$key] = stripslashes($value);
 }
}
}
if (get_magic_quotes_gpc()) // The php manual warns us... this wont work with magic_quotes_sybase
{
// Trust that its off =/
StripSlashArray_Deep($_GET);
StripSlashArray_Deep($_POST);
StripSlashArray_Deep($_COOKIE);
}
set_magic_quotes_runtime(0);
/*----------------------------------------------
           MAGIC QUOTES DISABLED
 
yay, they all gone, now you can use
  addslashes in safety...
----------------------------------------------*/


--------------------
User is offlineProfile CardPM
+Quote PostGo to the top of the page
post Oct 19 2004, 11:50 PM
Post #5


Member
Group Icon

Group: Regular Member
Posts: 23
Joined: 19-October 04
Member No.: 3,937




ternary operators : a nice way to get around ugly if(){}else{} statements...

you can use a ternary operator like this:
CODE
strlen($string)>10 ? $var=$greaterVar : $var=$smallerVar;

instead of going about it this way:
CODE
if(strlen($string)>10){
 $var = $greaterVar;
 }
else{
 $var = $smallerVar;
 }


this is how it works:
condition ? value_if_true : value_if_false;
if "condition" is true, the expression will equal "value_if_true". If not, it will equal "value_if_false".


--------------------
User is offlineProfile CardPM
+Quote PostGo to the top of the page
post Mar 8 2005, 03:20 AM
Post #6


Member
Group Icon

Group: Regular Member
Posts: 25
Joined: 4-March 05
From: lost
Member No.: 4,395

Sex: Male



use
CODE
$text = file_get_contents($filePath);

to get the contents of a text file instead of
CODE
$fp = fopen($filePath, "r");
$data = fread($fp, 1024);
$text = nl2br($data);
fclose($fp);


this is a feature added in newer versions of PHP.


--------------------
...only dead fish go with the flow.
User is offlineProfile CardPM
+Quote PostGo to the top of the page
post Mar 17 2005, 05:20 AM
Post #7


~Pulsage~
Group Icon

Group: Regular Member
Posts: 551
Joined: 1-May 02
From: South Africa - Gauteng
Member No.: 179

Sex: Male



Here is a link that some of you PHP programmers would find interesting, replacing single quotes with double quotes,

sounds rediciously, but read first ... hehe

SitePoint link

Pulse

This post has been edited by Pulse: Mar 17 2005, 05:21 AM


--------------------

IPB Image
IPB Image
User is offlineProfile CardPM
+Quote PostGo to the top of the page
post Mar 17 2005, 06:30 AM
Post #8


Full Member
Group Icon

Group: Regular Member
Posts: 574
Joined: 25-February 04
From: JHB
Member No.: 2,671

Sex: Male



ever tried to make a multiple selection dropdown box ?

well here is one

CODE
<?
if (isset($sub)) {
  for ($x=0;$x<count($sel);$x++) {
     echo $sel[$x]."<br>\n";
  } // end for

echo '<br>';
}
?>
<html>
<title>Multi Select Dropdown Box</title>
<body>
 <form method="POST" name="frm">
        <select size="6" name="sel[]" multiple="multiple">
           <option value='1'>1</option>
           <option value='2'>2</option>
           <option value='3'>3</option>
           <option value='4'>4</option>
           <option value='5'>5</option>
           <option value='0'> ------------- </option>
        </select>
  <input type="submit" name="sub">
 </form>
</body>
</html>
User is offlineProfile CardPM
+Quote PostGo to the top of the page
post Mar 17 2005, 10:31 AM
Post #9


:o 'o' o:
Group Icon

Group: Regular Member
Posts: 270
Joined: 11-August 02
Member No.: 530




PNG Semi-Transparent images are, err useful ?
They can be really useful, but unfortunately they dont work in Internet Explorer...

Since most of the market, is internet explorer based, there is a neat javascript based fix

http://homepage.ntlworld.com/bobosola/pnghowto.htm
Try it smile.gif

And while you at it, sign the petition to get Microsoft to add proper PNG support
http://www.petitiononline.com/msiepng/petition.html

Heres an, err, sample image ?
Taken from the site listed above, transparent pngs rawk. punk.gif
user posted image
User is offlineProfile CardPM
+Quote PostGo to the top of the page
post Mar 25 2005, 08:00 AM
Post #10


Lilium Inter Spinas
Group Icon

Group: Administration
Posts: 788
Joined: 24-June 02
From: Johannesburg, ZA
Member No.: 383

Sex: Male



I wrote this recently - please gimme feedback on the site and feel free to suggest additions - otherwise, if you looking for tips on SEO its really worth a read!
Guide to SEO
User is offlineProfile CardPM
+Quote PostGo to the top of the page
post Dec 9 2005, 07:24 AM
Post #11


Advanced Member
Group Icon

Group: Regular Member
Posts: 229
Joined: 23-November 02
From: Durban South Africa
Member No.: 742

Sex: Male



QUOTE(zaMob @ Oct 20 2004, 08:50 AM) *

ternary operators : a nice way to get around ugly if(){}else{} statements...

you can use a ternary operator like this:
CODE
strlen($string)>10 ? $var=$greaterVar : $var=$smallerVar;

instead of going about it this way:
CODE
if(strlen($string)>10){
 $var = $greaterVar;
 }
else{
 $var = $smallerVar;
 }


this is how it works:
condition ? value_if_true : value_if_false;
if "condition" is true, the expression will equal "value_if_true". If not, it will equal "value_if_false".


zaMob you got it all wrong
CODE
strlen($string)>10 ? $var=$greaterVar : $var=$smallerVar;

should be
CODE
$var = strlen($string)>10 ? $greaterVar : $smallerVar;

thats what the ternary operator is about


--------------------
Recursion /ree-ker'-zhon/: See Recursion.
User is offlineProfile CardPM
+Quote PostGo to the top of the page

Reply to this topicStart new topic



 



- Lo-Fi Version Time is now: 11th March 2010 - 05:55 PM
Privacy Policy
South Africa's Top Sites Kinetiq