sábado, 31 de diciembre de 2016
pass generator
<?php
$pass=array();
$counter=0;
while($counter<10){
$mypass=md5(uniqid());
$counter++;
$pass[]=$mypass;
}
foreach($pass as $key=>$value){
echo " $key $value<br>";
}
?>
0 1f961b78e85906401356b23e65a374bf
1 0540b8d52ae90ecaf0e1eb4027e908f3
2 10c3d35027da7c0d8d0fefc3a101177f
3 86f807889e034ec7c056574faada2a62
4 d834150988c5092435cdb7fbdb2a9260
5 250933f632c07d78e270dffd058599b4
6 f347b529da6c408f3e369e05aa7cdd20
7 9ed8d40fa3b22c0398eddf585de8c0b4
8 40c881c95fa9f2d914a2f5c308a7a6ca
9 cd1c77213b4ee5eec59246423c16f780
scrapping the first 2 pages of freelancer.com
<?php $offset=1; $increment=1; $list=array(); $data=shell_exec("curl https://www.freelancer.com/jobs/s-Asterisk_PBX-VoIP/$offset/?cl=l-en-es | grep -w \"https://www.freelancer.com/projects\""); $info=explode("\n",$data); foreach($info as $key=> $value) { if(!empty($value)){ //echo " $key : $value<br>"; $list[]=$value; } } if(end($list)){ $offset+=$increment; $data=shell_exec("curl https://www.freelancer.com/jobs/s-Asterisk_PBX-VoIP/$offset/?cl=l-en-es | grep -w \"https://www.freelancer.com/projects\""); $info=explode("\n",$data); foreach($info as $key=> $value) { if(!empty($value)){ //echo " $key : $value<br>"; $list[]=$value; } } } //new block to display both pages merges foreach($list as $key=> $value) { //echo ($key+1)." ".trim(strip_tags($value,"<a>")); echo " $key $value<br><br>"; } ?>
viernes, 30 de diciembre de 2016
freelancer scrapper
freelancer.php
<?php
$offset="1";
$list=array();
$data=shell_exec("curl https://www.freelancer.com/jobs/Asterisk-PBX/$offset/ | grep -w \"https://www.freelancer.com/projects\"");
$info=explode("\n",$data);
foreach($info as $key=> $value) {
if(!empty($value)){
echo " $key : $value <br>";
}
}
?>
This second script load the page in real time every 1 second
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script>
var auto_refresh = setInterval(
function()
{
$('#loaddiv').load('freelancer.php');
}, 1000);
</script>
<body>
<div id="loaddiv">
</div>
</body>
</html>
<?php
$offset="1";
$list=array();
$data=shell_exec("curl https://www.freelancer.com/jobs/Asterisk-PBX/$offset/ | grep -w \"https://www.freelancer.com/projects\"");
$info=explode("\n",$data);
foreach($info as $key=> $value) {
if(!empty($value)){
echo " $key : $value <br>";
}
}
?>
This second script load the page in real time every 1 second
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script>
var auto_refresh = setInterval(
function()
{
$('#loaddiv').load('freelancer.php');
}, 1000);
</script>
<body>
<div id="loaddiv">
</div>
</body>
</html>
martes, 27 de diciembre de 2016
php check letter
<?php
$str="jdddl1sssssssdkdsfdnfdkfdfdnkkd8";
$arr1 = str_split($str);
foreach($arr1 as $value){
if(!ctype_alpha($value)) {
echo " $value is not a letter<br>";
}
?>
$str="jdddl1sssssssdkdsfdnfdkfdfdnkkd8";
$arr1 = str_split($str);
foreach($arr1 as $value){
if(!ctype_alpha($value)) {
echo " $value is not a letter<br>";
}
?>
lunes, 26 de diciembre de 2016
php filter
<?php
$number=filter_var('bobexample.com1111',FILTER_SANITIZE_NUMBER_INT);
echo $number;
echo "<br>";
var_dump($number=filter_var('10.0.0.1888',FILTER_VALIDATE_IP))
?>
1111 ( Sanatize )
bool(false) (evaluate)
$number=filter_var('bobexample.com1111',FILTER_SANITIZE_NUMBER_INT);
echo $number;
echo "<br>";
var_dump($number=filter_var('10.0.0.1888',FILTER_VALIDATE_IP))
?>
1111 ( Sanatize )
bool(false) (evaluate)
Check if the external variable "email" is sent to the PHP page, through the "get" method, and also check if it is a valid email address:
<?php
if (!filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL)) {
echo("Email is not valid");
} else {
echo("Email is valid");
}
?>
Spliingt an array into chunks
<?php
$list=array("nancy","robert","john");
//print_r( array_change_key_case($list,CASE_UPPER));
print_r(array_chunk ($list,2));
$list=array_chunk ($list,2);
echo"<br>";
echo"<br>";
echo $list[0][1]; //value for second key on first array
echo"<br>";
echo $list[1][0]; //value for first key on second array
?>
Array ( [0] => Array ( [0] => nancy [1] => robert ) [1] => Array ( [0] => john ) )
robert
john
the list array will be splited in 2 arays
$list=array("nancy","robert","john");
//print_r( array_change_key_case($list,CASE_UPPER));
print_r(array_chunk ($list,2));
$list=array_chunk ($list,2);
echo"<br>";
echo"<br>";
echo $list[0][1]; //value for second key on first array
echo"<br>";
echo $list[1][0]; //value for first key on second array
?>
Array ( [0] => Array ( [0] => nancy [1] => robert ) [1] => Array ( [0] => john ) )
robert
john
the list array will be splited in 2 arays
domingo, 25 de diciembre de 2016
array_column
(PHP 5 >= 5.5.0, PHP 7)
array_column — Return the values from a single column in the input array
Parameters ¶
input
- A multi-dimensional array or an array of objects from which to pull a column of values from. If an array of objects is provided, then public properties can be directly pulled. In order for protected or private properties to be pulled, the class must implement both the __get() and __isset() magic methods.
column_key
- The column of values to return. This value may be an integer key of the column you wish to retrieve, or it may be a string key name for an associative array or property name. It may also be
NULL
to return complete arrays or objects (this is useful together withindex_key
to reindex the array). index_key
- The column to use as the index/keys for the returned array. This value may be the integer key of the column, or it may be the string key name.
Return Values ¶
Returns an array of values representing a single column from the input array.
Changelog ¶
Version | Description |
---|---|
7.0.0 | Added the ability for the input parameter to be an array of objects. |
viernes, 23 de diciembre de 2016
php scrapper
<?php $offset="0"; $increment=7; $string="oferta"; $list=array(); //echo "<a href=http://www.aldaba.com/ver_ofertas.php?offset=$offset&area=s%3A19%3A%22Ingenier%EDa+Sistemas%22%3B&pais=Rep%FAblica+Dominicana&ln=83&oby=dt target=_blank> Aldaba.org</a><br>"; $data=shell_exec("curl \"http://www.aldaba.com/ver_ofertas.php?offset=$offset&area=s%3A19%3A%22Ingenier%EDa+Sistemas%22%3B&pais=Rep%FAblica+Dominicana&ln=83&oby=dt\" | grep -i ficha "); $info=explode("<b>",$data); foreach($info as $key=> $value) { if($key>0){ $list[]=$value; } } while(end($info)){ $offset+=$increment; if (count($info)<8) { break; } $data=shell_exec("curl \"http://www.aldaba.com/ver_ofertas.php?offset=$offset&area=s%3A19%3A%22Ingenier%EDa+Sistemas%22%3B&pais=Rep%FAblica+Dominicana&ln=83&oby=dt\" | grep -i ficha"); $info=explode("<b>",$data); foreach($info as $key=> $value) { if($key>0){ $list[]=$value; } } } foreach($list as $key=> $value) { echo "<br>"; echo ($key+1)." ".trim(strip_tags($value,"<a>"))."<br>"; } ?>
sábado, 17 de diciembre de 2016
php reset
Example #1 reset() example
<?php
$array = array('step one', 'step two', 'step three', 'step four');
// by default, the pointer is on the first element
echo current($array) . "<br />\n"; // "step one"
// skip two steps
next($array);
next($array);
echo current($array) . "<br />\n"; // "step three"
// reset pointer, start again on step one
reset($array);
echo current($array) . "<br />\n"; // "step one"
?>
reset() rewinds
array
's internal pointer to the first element and returns the value of the first array element.Parameters ¶
array
- The input array.
Return Values ¶
Returns the value of the first array element, or
FALSE
if the array is empty.$array = array('step one', 'step two', 'step three', 'step four');
// by default, the pointer is on the first element
echo current($array) . "<br />\n"; // "step one"
// skip two steps
next($array);
next($array);
echo current($array) . "<br />\n"; // "step three"
// reset pointer, start again on step one
reset($array);
echo current($array) . "<br />\n"; // "step one"
?>
viernes, 16 de diciembre de 2016
fread get contents of a file into a string
<php
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
?>
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
?>
Example use of current() and friends
<?php
$transport = array('foot', 'bike', 'car', 'plane');
$mode = current($transport); // $mode = 'foot';
$mode = next($transport); // $mode = 'bike';
$mode = current($transport); // $mode = 'bike';
$mode = prev($transport); // $mode = 'foot';
$mode = end($transport); // $mode = 'plane';
$mode = current($transport); // $mode = 'plane';
$transport = array('foot', 'bike', 'car', 'plane');
$mode = current($transport); // $mode = 'foot';
$mode = next($transport); // $mode = 'bike';
$mode = current($transport); // $mode = 'bike';
$mode = prev($transport); // $mode = 'foot';
$mode = end($transport); // $mode = 'plane';
$mode = current($transport); // $mode = 'plane';
?>
jueves, 15 de diciembre de 2016
Array comparison
array_diff_assoc
Compares array1 against array2 and returns the difference. Unlike array_diff() the array keys are also used in the comparison.
array_diff_key
Compares the keys from array1 against the keys from array2 and returns the difference. This function is like array_diff() except the comparison is done on the keys instead of the values.
array_diff
Compares array1 against one or more other arrays and returns the values in array1 that are not present in any of the other arrays.
array_diff_ukey
Compares the keys from array1 against the keys from array2 and returns the difference. This function is like array_diff() except the comparison is done on the keys instead of the values.
Compares array1 against array2 and returns the difference. Unlike array_diff() the array keys are also used in the comparison.
array_diff_key
Compares the keys from array1 against the keys from array2 and returns the difference. This function is like array_diff() except the comparison is done on the keys instead of the values.
array_diff
Compares array1 against one or more other arrays and returns the values in array1 that are not present in any of the other arrays.
array_diff_ukey
Compares the keys from array1 against the keys from array2 and returns the difference. This function is like array_diff() except the comparison is done on the keys instead of the values.
viernes, 9 de diciembre de 2016
writing data to a file file_put_contents()
This function is identical to calling fopen(), fwrite() and fclose() successively to write data to a file.
<?php
$file="/var/www/htm/data.txt";
$data=$argv[1];
$data.="\n";
file_put_contents("$file", $data,FILE_APPEND);
?>
php write.php "ambiorix rodriguez placencio"
jueves, 8 de diciembre de 2016
checking if a key and value exist
<?php
$r = array('a', 'robert', 'c', 'd', 'e'=>"robert");
print_r(array_keys($r,'robert'));
?>
check if the value robert exist and return an array with the key where each value is found
Array ( [0] => 1 [1] => e )
robert is on key 1 and key e
a more complex a sample and clean example
<?php
$r = array('a', 'robert', 'c', 'd', 'e'=>"robert");
if($key=array_keys($r,'robert'));
foreach($key as $value) {
echo $value."<br>";
}
this will return only the keys name
1
e
$r = array('a', 'robert', 'c', 'd', 'e'=>"robert");
print_r(array_keys($r,'robert'));
?>
check if the value robert exist and return an array with the key where each value is found
Array ( [0] => 1 [1] => e )
robert is on key 1 and key e
a more complex a sample and clean example
<?php
$r = array('a', 'robert', 'c', 'd', 'e'=>"robert");
if($key=array_keys($r,'robert'));
foreach($key as $value) {
echo $value."<br>";
}
this will return only the keys name
1
e
Suscribirse a:
Entradas (Atom)
input
, identified by thecolumn_key
. Optionally, anindex_key
may be provided to index the values in the returned array by the values from theindex_key
column of the input array.