Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?
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);
}
<?
$percent = substr($num, 0, ((strpos($num, '.')+1)+2)); //9.99
<?
$csv = explode("\n", file_get_contents('http://test.csv'));
foreach ($csv as $key => $line)
{
$csv[$key] = str_getcsv($line);
}
<?php
$d = 'path/to/images/';
foreach(glob($d.'*.{jpg,JPG,jpeg,JPEG,png,PNG}',GLOB_BRACE) as $file){
$imag[] = basename($file);
}
<?
$map = [
'Red Post' => 'Awesome Post',
'Green Post' => 'Crazy Post',
'Blue Post' => 'Insane Post'
];
$data = str_replace( array_keys( $map ), $map, $data );
<?
$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;
<?
//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;
}
<?
$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>';
?>
<?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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment