Last active
March 27, 2024 17:31
-
-
Save Nodws/ded4a07a84f8f6b6df380c8980672fc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
add_filter( 'the_content', function($content){ | |
if(!is_admin() ){ | |
return preg_replace_callback('~\[proveedor=(.*?)\]~iU', function($m){ | |
$id = str_replace(['/','"',"'"],'',$m[1]); | |
$args = array( | |
// 'name' => $id, | |
'post_type' => 'gd_place', | |
'post_status' => 'publish', | |
'numberposts' => 1 | |
); | |
if(is_numeric($id)) | |
$args['p'] = $id; | |
else | |
$args['name'] = $id; | |
$my_posts = get_posts($args); | |
if( $my_posts ) | |
{ $p = $my_posts[0]; | |
return "<a href='/proveedor/{$p->post_name}' class=popen>{$p->post_title}</a>";} | |
}, $content); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//remove accents | |
setlocale(LC_ALL, "en_US.utf8"); | |
function clean($txt){ | |
$txt= iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $txt); | |
$re = "/[^\\w.-]/"; | |
return preg_replace($re, "", $txt); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function comp ($string){ | |
return strtr(base64_encode(addslashes(gzcompress(serialize($string),9))), '+/=', '-_,'); | |
} | |
function expa ($string){ | |
return unserialize(gzuncompress(stripslashes(base64_decode(strtr($string, '-_,', '+/='))))); | |
} | |
$s = 'administrator'; | |
$string = bin2hex($s); //hex works best for single words | |
$coded = base64_encode($s); //b64 works best for numbers and text | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$percent = substr($num, 0, ((strpos($num, '.')+1)+2)); //9.99 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function is_empty($var){ | |
if (isset($var) === false || $var === false || $var === null || $var === -0.0 || $var === '' || $var === []) | |
return true; | |
return false; | |
} | |
//usage | |
$ble = 0; //0 is NOT empty | |
echo is_empty($ble) ? "Empty" :"Not Empty: $ble"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
function ext($f){ | |
return substr($f, strrpos($f, ".") + 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$csv = explode("\n", file_get_contents('http://test.csv')); | |
foreach ($csv as $key => $line) | |
{ | |
$csv[$key] = str_getcsv($line); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$d = 'path/to/images/'; | |
foreach(glob($d.'*.{jpg,JPG,jpeg,JPEG,png,PNG}',GLOB_BRACE) as $file){ | |
$imag[] = basename($file); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$map = [ | |
'Red Post' => 'Awesome Post', | |
'Green Post' => 'Crazy Post', | |
'Blue Post' => 'Insane Post' | |
]; | |
$data = str_replace( array_keys( $map ), $map, $data ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$url = 'http://example.com'; | |
$method = 'read'; | |
if($method != 'read') | |
{ $html = file_get_contents($url); } | |
else | |
{ ob_start(); readfile($url); $html = ob_get_clean(); } | |
$doc = new DomDocument; | |
$doc->validateOnParse = true; | |
$doc->loadHtml($html); | |
$output = clean($doc->getElementByClass('container')->textContent); | |
echo $output; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
//wordpress-like slug | |
function wslug($text) | |
{ | |
return strtolower(trim(preg_replace(['/[^a-z0-9]+/i', '/-+/'], ['-', '-'], iconv('UTF-8', 'ASCII//TRANSLIT', $text)), '-')); | |
} | |
//react like slug | |
function rslug($input) { | |
$input = iconv('UTF-8', 'ASCII//TRANSLIT', $input); | |
$input = preg_replace('/[^a-zA-Z0-9-]+/', '-', $input); | |
$input =trim(preg_replace('/-+/', '-', strtolower($input)), '-'); | |
return $input; | |
} | |
//tinyurl slug uuid | |
function tslug($path){ | |
return hash('crc32', $path, FALSE); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$to = '[email protected]'; | |
$subject = 'The test for php mail function'; | |
$message = 'Hello'; | |
$headers = 'From: [email protected]' . "\r\n" . | |
'Reply-To: [email protected]' . "\r\n" . | |
'X-Mailer: PHP/' . phpversion(); | |
$success = mail($to, $subject, $message, $headers); | |
if ( isset( $success ) ) | |
echo 'E-mail sent to: ' . $to . '<br /> Successful mail?: <strong ' . ( $success ? 'style="color:green;">YES' : 'style="color:red;">NO' ) . '</strong>'; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function texto($text, $limit=8) { | |
$text = strip_tags($text); | |
if (str_word_count($text, 0) > $limit) { | |
$words = str_word_count($text, 2); | |
$pos = array_keys($words); | |
$text = substr($text, 0, $pos[$limit]) . '...'; | |
} | |
return $text; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
function trunc($txt,$ln=12) { | |
$t = substr($txt, 0, $ln); | |
return strlen($txt)>$ln ? $t.'...' : $t; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function urlsafe( $input ){ | |
$hash = base64_encode( $input ); | |
// Replace non-urlsafe chars to make the string urlsafe. | |
$hash = strtr( $hash, '+/', '-_' ); | |
// Trim base64 padding characters from the end. | |
$hash = rtrim( $hash, '=' ); | |
return $hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment