Iterating through Key- Value Pair Array using PHP 
foreach ($array as $key => $value)
{
//code block statements that run inside foreach loop
}




[ view entry ] ( 1221 views )   |  print article
Code to populate mysql with random data (needs some cleaning) 
CREATE TABLE `RandomNumbers_InnoDB` (
`id` int(11) NOT NULL auto_increment,
`random1` varchar(100) default NULL,
`random2` varchar(100) default NULL,
`random3` varchar(100) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Sample ouput:
http://www.angelcool.net/tutorials/othe ... 00rows.txt


<?php
set_time_limit(0);

function db_link()
{




//@ suppresses the error mysqli_connect returns, and instead we use our die() error
$db_link=mysqli_connect('127.0.0.1','root','');




if($db_link==false)
echo 'Could NOT connect to MySQL, check mysqli_connect settings. ';


//select database
if(@mysqli_select_db($db_link,'test')==false)
echo 'Could NOT select DB, check DB name.';


return $db_link;

}



function String()
{
//Step 1 Generate a token.
$length = 32;
$chars = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789'; //ABCDEFGHIJKLMNPQRTWXYZ123456789 123456789abcdefghijklmnopqrstwxzABCDEFGHIJKLMNPQRTWXYZ
$string = '';
for ($i = 0; $i < $length; $i++) {
$pos = rand(0, strlen($chars)-1);
$string .= $chars{$pos}; }

return $string;

}




/*
How many different 4-letter combinations are there in the alphabet?
letters in alphabet = 26

Answer:
26^4 = 456,976
There are 26 choices for the first letter, 26 for the second, 26 for the 3rd and 26 for the 4th. So altogether, there are 26*26*26*26 = 456,976 combinations.

I hope this helps!

http://answers.yahoo.com/question/index ... 851AAkpgEj
*/

$conn=db_link();
echo '<b>'.date(DATE_RFC822).'</b>';

$execution_time=microtime(true);

for($iii=1;$iii<=200;)
{
$start=microtime(true);



/*

//Run this query to find out duplicate tokens
SELECT * FROM BulkTokens INNER JOIN (SELECT Token,COUNT(Token) AS Duplicated FROM BulkTokens
GROUP BY Token HAVING Duplicated > 1) dup ON BulkTokens.Token=dup.Token;


*/

$string1=String(); $string2=String(); $string3=String();

//Step 2 Check if token DOES NOT exist in database (check if it is duplicated, if it is skip this iteration).
// $query="SELECT random1 FROM RandomNumbers_InnoDB WHERE BINARY random1='".$string1."' and random2='".$string2."' and random3='".$string3."'";
// $result=mysqli_query($conn,$query) or die(mysqli_error($conn));
// $query=mysqli_num_rows($result);



//if token exists skip iteration.mysqli_num_rows($query)==0
if(true)//$query==0
{

//If token does not exist add 1 to $iii and assign the token to array.



// and insert it in database.
$query="INSERT INTO RandomNumbers_InnoDB(random1,random2,random3) VALUES('".$string1."','".$string2."','".$string3."');";
mysqli_query($conn,$query) or die(mysqli_error($conn));
echo $iii.'----'.$string1.'----'.$string2.'----'.$string3.' Iteration execution time:'.round((microtime(true)-$start),4).' secs<br>';
$iii++;

}
else
{ echo '====================================================================================================SKIPPED REPEATED RECORD !!';}



}
echo '<br><br><br>Total Execution Time:'.round((microtime(true)-$execution_time),4).'<br><br><br>';

echo '<b>'.date(DATE_RFC822).'</b>';

?>


[ view entry ] ( 1245 views )   |  print article
HOSTS file location 
#Win7
C:\windows\system32\drivers\etc\ or %systemroot%\system32\drivers\etc\


#CentOS
/etc/hosts

[ view entry ] ( 1157 views )   |  print article
Setting up PDFlib extension in PHP 
1.- Download PDFlib-8.0
2.- Look for libpdf_php.so
3.- Copy and paste to extension_dir [ see phpinfo() ]
4.- Add extension in php.ini

extension=libpdf_php.so

5.- Restart httpd and check PDFlib support in phpinfo()
6.- Get a license ($) to remove watermark.

Or try fpdf and fpdi.

[ view entry ] ( 1200 views )   |  print article
PHP Easter Egg 
file.php?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000 - PHP Credits
PHPE9568F34-D428-11d2-A769-00AA001ACF42 - PHP Logo
PHPE9568F35-D428-11d2-A769-00AA001ACF42 - Zend Logo
PHPE9568F36-D428-11d2-A769-00AA001ACF42 - Easter Egg

[ view entry ] ( 1223 views )   |  print article
.htaccess notes 
# This will pop-up a user/password dialog box saying Realm =
AuthName "Restricted Area"

# AuthType is normally basic. Not very secure until "Digest" type becomes prevalent
AuthType basic

# If value of AuthUserFile doesn't begin with a slash, it is treated as
# relative to the ServerRoot (not DocumentRoot!)
AuthUserFile "/userhome/blahBlah/.htpasswd"
AuthGroupFile "/userhome/blahBlah/.htgroup"

#Custom icons
AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/text.gif .txt
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^
# If no file type matches..
DefaultIcon /icons/unknown.gif

...more to come.

[ view entry ] ( 1749 views )   |  print article
Populating a PDF file with XFDF using PDFTK command. 
pdftk InvoiceTemplate.pdf fill_form InvoiceData.xfdf output - flatten > InvoiceXXXX.pdf


[ view entry ] ( 1781 views )   |  print article
Moonbeam - Reaching beyond the stars! 
Moonbeam! Relax and enjoy, music for the soul. These Russian guys really make me think outside the box, the best. You should really check them out.

http://www.youtube.com/watch?v=tk1VKcsfbYM

Albums:
Around the world
Consumption
Storm of Clouds (Sky !)

...and podcasts.

[ view entry ] ( 1698 views )   |  print article
Binary, Octal & Hexadecimal to Decimal Conversion (Manual Process) 
I wrote this tutorial to demonstrate how to manually convert from binary,octal or hexadecimal to decimal.

http://www.angelcool.net/tutorials/misc ... ecimal.pdf

[ view entry ] ( 1996 views )   |  print article
Web Development Network Setup with NVI 
The goal of the tutorial is to allow NATed and Internet hosts to use a public IP to access the NATed development server, fixing DNS issues.

Click the link to see tutorial.
http://www.angelcool.net/tutorials/cisc ... rk_NVI.pdf

[ view entry ] ( 1438 views )   |  print article

<<First <Back | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Next> Last>>


2024 By Angel Cool