PHP/HTML


Oct
19

0


PHP Show Errors

{code type=php}<?php
//show all possible errors
error_reporting(E_ALL);
//overrides php.ini setting
ini_set(‘display_errors’, ’1′);
?>
{/code}

PHP Hide Errors

{code type=php}<?php
//hide all possible errors
error_reporting(0);
//overrides php.ini setting
ini_set(‘display_errors’, ’0′);
?>
{/code}

php.ini Show Errors

{code type=php}
//this should go in the php.ini file
display_errors = On
{/code}

php.ini Hide Errors

{code type=php}
//this should go in the php.ini file
display_errors = Off
{/code}

PHP Error Handling Options

{code type=php}<?php
// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings …)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set(‘error_reporting’, E_ALL);
?>
{/code}

Oct
14

0


Insert this block of code at the very top of your page:
{code type=php} <?php
$time = microtime();
$time = explode(” “, $time);
$time = $time[1] + $time[0];
$start = $time;
?> {/code}

Place this part at the very end of your page
{code type=php} <?php
$time = microtime();
$time = explode(” “, $time);
$time = $time[1] + $time[0];
$finish = $time;
$totaltime = ($finish – $start);
printf (“This page took %f seconds to load.”, $totaltime);
?> {/code}

May
30

0


{code type=”php”}
function limit($string, $limit = “20″, $ellipses = “1″) {
//dont mess with string if it is smaller than limit!
if (strlen($string) <= $limit) return $string;

//add some flare with ellipses--------------length of elips
if ($ellipses == "1") { $ellips = "..."; $ecnt = "3"; }
if ($ellipses == "2") { $ellips = "|...|"; $ecnt = "5"; }
if ($ellipses == "3") { $ellips = "|~|"; $ecnt = "3"; }
if ($ellipses == "4") { $ellips = "↜|↝"; $ecnt = "3"; }
if ($ellipses == "5") { $ellips = "↭"; $ecnt = "1"; }

//length of ellipses will be subtracted from limit so new string meets limit
$limitu = ceil(($limit - $ecnt) / 2);
$limitd = floor(($limit - $ecnt) / 2);

//only useful if string is a url // common knowledge - anything followed by .com is a web address
$string = str_replace("http://", '', $string);
$string = str_replace("www.", '', $string);

//actual trim process
$left = substr($string, 0, $limitu);
$right = substr($string, -$limitd);

return $left . $ellips . $right;
}

//example usage with results commented out
$string = “abcdefghijklmnopqrstuvwxyz”; //(26 characters)
“;

$test1 = limit($string,5,4); // a…z //( 5 characters)
“;
$test2 = limit($string,10,4); // abc|…|yz //(10 characters)
“;
$test3 = limit($string,15,4); // abcdef|~|uvwxyz //(15 characters)
“;
$test4 = limit($string,20,4); // abcdefghi↜|↝stuvwxyz //(20 characters)
“;
$test5 = limit($string,25,4); // abcdefghijkl↭opqrstuvwxyz //(25 characters)
“;
$test6 = limit($string,30,4); // abcdefghijklmnopqrstuvwxyz //(26 characters)
“;

{/code}

Apr
30

PHP Cleaning

Posted in PHP/HTML by Admin

0


{code type=”php”} mysql_real_escape_string() {/code} for functional mysql_* calls (although it’s better to use parametrized queries if you have the choice)


{code type=”php”} htmlspecialchars() {/code} for safe HTML output


{code type=”php”} preg_quote() {/code} for use in a regular expression


{code type=”php”} escapeshellarg() / escapeshellcmd() {/code} for use in an external command


{code type=”php”}
if(get_magic_quotes_gpc())
echo “Magic quotes are enabled”;
else
echo “Magic quotes are disabled”;
{/code}

Mar
31

0


Pick Up Javascript

{code type=”php”}
$string = ‘<script>document.write(” foo bar car star “);</script>’; OR
$string = ‘<script type=”text/javascript”>document.write(” foo bar car star “);</script>’;
preg_match(‘/(<script.*>{1})(.*?)(<\/script>)/i’, $string2, $matches);
print_r($matches);
{/code}

{code type=”php”}
Array
(
[0] => <script type=”text/javascript”>document.write(” foo bar car star “);</script>
[1] => <script type=”text/javascript”>
[2] => document.write(escape(” foo bar car star “));
[3] => </script>
)
{/code}

{code type=”php”}
$matches['0'] entire js script
$matches['1'] opening tag
$matches['2'] js script
$matches['3'] closing tag
{/code}

You can manipulate the js code $matches['2'] as needed, then reassemble with the original js tags.

{code type=”php”}
<?php
//caps first letter of each word
$new_js = ucwords(strtolower($matches['2']));
//reassembles the whole code
echo $matches['1'].$new_js.$matches['3']; ?>
//old code
<script type=”text/javascript”>document.write(” foo bar car star “);</script>
//new code
<script type=”text/javascript”>Document.write(” Foo Bar Car Star “);</script>
{/code}

Mar
11

0


cat /proc/loadavg
This file provides a look at the load average in regard to both the CPU and IO over time, as well as additional data used by uptime and other commands.

CPU/IO Usage of Last Minute CPU/IO Usage of Last 5 Minutes CPU/IO Usage of Last 10 Minutes Processes Current/Total Last Process ID
 
0.10 0.20 0.20 1/100 12345

{code type=php} <?php
echo exec(‘cat /proc/loadavg’);
echo shell_exec(‘cat /proc/loadavg’);
system(‘cat /proc/loadavg’);
?> {/code}


cat /proc/uptime
This file contains two numbers: the uptime of the system (seconds), and the amount of time spent in idle process (seconds).

Seconds the server has been running Seconds the server has spent in idle
 
1594971.72 1015416.92

{code type=php} <?php
echo exec(‘cat /proc/uptime’);
echo shell_exec(‘cat /proc/uptime’);
system(‘cat /proc/uptime’);
?> {/code}

Dec
22

0


HTML 4 Transitional
{code type=php}
"http://www.w3.org/TR/html4/loose.dtd">
{/code}

HTML 4 Strict
{code type=php}
"http://www.w3.org/TR/html4/strict.dtd">
{/code}

XHTML Transitional
{code type=php}
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
{/code}

XHTML Strict
{code type=php}
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
{/code}

Set Lang
{code type=php}

{/code}

Set UTF
{code type=php}

or

{/code}

No Cacheing
{code type=php}


{/code}

Force IE 8 To Act As IE 7
{code type=php}

{/code}

Other Compatibility Settings
{code type=php}

{/code}

Other Stuff
{code type=php}








{/code}


Not meta, but while Im here:
Style Tag
{code type=php}

{/code}

Script Tag
{code type=php}

{/code}


Quick Start

Watch closely for commented tags!

{code type=php}
































Checkout Our Friends at FremontTech


{/code}

Nov
2

0


This little guy will subtract the values of one array from another array and create a new array with the differences
{code type=php}<?php
$array1 = array(15,17,25,2);
$array2 = array(25,37,50,4);

// next four lines are not needed, but you added for visual conformation
print_r($array2);
echo “
“;
print_r($array1);
echo “


“;

// only $countA is needed, the other 3 lines are for debugging
$countA=count($array1);
//echo $countA.”
“;
$countB=count($array2);
//echo $countB.”
“;

//Now for the actual math
for($i=0;$i<$countA;$i++){
$new_array[] = $array2[$i] – $array1[$i];
}

// show the new array which is array2[values] subtracted from array1[values]
print_r($new_array);
?>
{/code}

Nov
2

0


{code type=php}
<?php
$file = “filename.ext”;
$lines = count(file($file));
echo “There are $lines lines in $file”;
?>
{/code}

Oct
28

PHP Page

Posted in PHP/HTML by Admin

0


Getting the page name with php

{code type=php}<?php
$currentFile = $_SERVER["PHP_SELF"];
$parts = Explode(‘/’, $currentFile);
$page=$parts[count($parts) - 1];
?>{/code}

{code type=php}<?php if ($page==”index.php”) { ?>
<link rel=”stylesheet” type=”text/css” href=”style_for_index.css” />
<? } ?>{/code}

Getting the subdomain with php

{code type=php}<?php
$currentFile = $_SERVER["HTTP_HOST"];
$parts = Explode(‘.’, $currentFile);
$domain=$parts[count($parts) - 3];
?>{/code}

{code type=php}<?php if ($domain==”index.php”) { ?>
<link rel=”stylesheet” type=”text/css” href=”style_for_index.css” />
<? } ?>{/code}

How to test to see what you are getting back

{code type=php}<?php echo $currentFile;?>
<?php print_r($parts)?>
<?php echo $domain;?>{/code}

Page 1 of 212