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 | |
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, '-_,', '+/='))))); | |
} |
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
<? | |
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 slug($text, $lower=true, $dashit=true,$utf=false) | |
{ | |
$text = preg_replace('/[^a-z\d ]/i','',transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC;", $text)); | |
if($utf) | |
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); | |
if($dashit) | |
$text = trim(preg_replace('~-+~', '-',preg_replace('~[^-\w]+~', '-', $text)), '-'); | |
if($lower) | |
$text = strtolower($text); | |
//return $text; | |
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
<? | |
$to = 'test@test.com'; | |
$subject = 'The test for php mail function'; | |
$message = 'Hello'; | |
$headers = 'From: test@test.com' . "\r\n" . | |
'Reply-To: test@test.com' . "\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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment