php naive.php

naive.php
<?php

/**
 * Naive Bayes classifier
 */

include __DIR__ . '/../vendor/autoload.php';

function train($samples)
{
    $samples_count = count($samples);
    $classes = [];
    $freq = [];

    foreach ($samples as $sample) {
        $label = $sample['label'];
        $classes[$label] = ($classes[$label] ?? 0) + 1;
        foreach ($sample['features'] as $feature) {
            $freq[$label][$feature] = ($freq[$label][$feature] ?? 0) + 1;
        }
    }
    foreach ($freq as $label => $features) {
        foreach ($features as $feature => $count) {
            $freq[$label][$feature] = $count / $classes[$label];
        }
    }
    foreach ($classes as $label => $count) {
        $classes[$label] = $count / $samples_count;
    }

    return (object) compact('classes', 'freq');
}

function classification($classifier, $features)
{
    $res = ['m' => PHP_INT_MAX, 'label' => null];
    foreach ($classifier->classes as $label => $p) {
        $m = -log($p) + collect($features)->sum(function ($feature) use ($classifier, $label) {
                return - log(array_get($classifier->freq, "{$label}.{$feature}", 10**(-7)));
            });
        if ($m < $res['m']) {
            $res = ['m' => $m, 'label' => $label];
        }
    }

    return $res['label'];
}

function extract_features($data)
{
    return str_split($data);
}


$samples = [
    ['label' => 'd', 'value' => '234'],
    ['label' => 'd', 'value' => 'e14'],
    ['label' => 'd', 'value' => '95094'],
    ['label' => 'd', 'value' => '456'],
    ['label' => 'w', 'value' => 'sdfsldf'],
    ['label' => 'w', 'value' => 'pwper'],
    ['label' => 'w', 'value' => 'eee'],
    ['label' => 'w', 'value' => 'ee1sd'],
    ['label' => 'w', 'value' => 'ee12d'],
];

foreach ($samples as &$sample) {
    $sample['features'] = extract_features($sample['value']);
}
unset($sample);

$classifier = train($samples);

$tests = [
    '180456',
    'mcnxc',
    's89sf66sdf',
    '001u',
    'e0091',
    'ccc',
];
foreach ($tests as $test) {
    echo $test . ': ' . classification($classifier, extract_features($test)) . PHP_EOL;
}

/**
 * output:
 *      180456: d
 *      mcnxc: w
 *      s89sf66sdf: w
 *      001u: d
 *      e0091: d
 *      ccc: w
 */

php aggiunge una colonna ordinabile nella vista sommario con la data dell'ultima modifica

aggiunge una colonna ordinabile nella vista sommario con la data dell'ultima modifica

ordina_ultima_modifica.php
add_filter( 'manage_edit-post_columns', 'aco_last_modified_admin_column' );

// Create the last modified column
function aco_last_modified_admin_column( $columns ) {
  $columns['modified-last'] =__( 'Last Modified', 'aco' );
  return $columns;
}

add_filter( 'manage_edit-post_sortable_columns', 'aco_sortable_last_modified_column' );

// Allow that content to be sortable by modified time information
function aco_sortable_last_modified_column( $columns ) {
  $columns['modified-last'] = 'modified';
  return $columns;
}

add_action( 'manage_posts_custom_column', 'aco_last_modified_admin_column_content', 10, 2 );

// Format the output
function aco_last_modified_admin_column_content( $column_name, $post_id ) {

  // Do not continue if this is not the modified column
  if ( 'modified-last' != $column_name )
    return;

  $modified_date   = the_modified_date( 'Y/m/d - g:i A' );
  $modified_author = get_the_modified_author();

  echo $modified_date;
  echo '<br>';
  echo '<strong>' . $modified_author . '</strong>';

}

php WordPress小部件

WordPress小部件

function.php
// Register and load the widget
function wpb_load_widget() {
	register_widget( 'wpb_widget' );
}
add_action( 'widgets_init', 'wpb_load_widget' );

// Creating the widget 
class wpb_widget extends WP_Widget {

function __construct() {
parent::__construct(

// Base ID of your widget
'wpb_widget', 

// Widget name will appear in UI
__('WPBeginner Widget', 'wpb_widget_domain'), 

// Widget description
array( 'description' => __( 'Sample widget based on WPBeginner Tutorial', 'wpb_widget_domain' ), ) 
);
}

// Creating widget front-end

public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );

// before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];

// This is where you run the code and display the output
echo __( 'Hello, World!', 'wpb_widget_domain' );
echo $args['after_widget'];
}
		
// Widget Backend 
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'wpb_widget_domain' );
}
// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php 
}
	
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
} // Class wpb_widget ends here

php Вытаскиваемценуизэлементаинфоблока。

Вытаскиваемценуизэлементаинфоблока。

index.php
<?	
		if(CModule::IncludeModule("catalog"))
					{
						$ar_price = GetCatalogProductPrice($arResult["ID"], 1);
						//Конвертируем валюту в рубли, вам может и не понадобится
						if(isset($ar_price['CURRENCY']) && $ar_price['CURRENCY']!="RUB") $ar_price['PRICE'] = CCurrencyRates::ConvertCurrency($ar_price['PRICE'], $ar_price["CURRENCY"], "RUB");
						//В переменной $price теперь содержится цена товара
						$price = $ar_price['PRICE'];
				}

php VirtualHost MAMP窗口

VirtualHost MAMP窗口

vhost_mamp_win_2.php
<VirtualHost *:80>
    DocumentRoot "F:/siti/nomesito"
    <Directory  "F:/siti/nomesito">
    Order allow,deny
    Allow from all
    Require all granted
    Satisfy Any
    </Directory>
    ServerName nomesito.it
    ServerAlias nomesito.it
</VirtualHost>
vhost_mamp_win.php
<VirtualHost *:80>
    DocumentRoot "D:\siti\laravel1\public"
    ServerName laravel1.dev
    <Directory "D:\siti\laravel1\public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Allow from all
    </Directory>
</VirtualHost>

php Diferencia entre fechas(BD)(PHP)

Diferencia entre fechas(BD)(PHP)

new_gist_file_0.php
	$hoy = new Fecha();
	$this->SgicTareas->PersonalReconocimiento->añadeFiltro("DATEDIFF('{$hoy->mysqlCompleto()}', PersonalReconocimiento.fecha) <=30");

php strm.hu侧边栏链接

strm.hu侧边栏链接

artist-sidebar-links.php
<?php
/**
 * Created by PhpStorm.
 * User: clvz
 * Date: 2017.05.24.
 * Time: 11:23
 */

global $tana_sidebar, $tana_sidebar_position;
$sidebar_id = 'sidebar';
$sidebar_class = array(
    'col-sm-3',
    'sidebar',
    'sticky-column',
    'mb2'
);
$sidebar_class[] = "area-" . $sidebar_id;
$sidebar_class = implode(' ', $sidebar_class);

// meta variables
$imguri = get_stylesheet_directory_uri();
/*
$spitify = echo $key_name = get_post_custom_values($key = 'Spotify'); echo $key_name[0];
$gplay = echo $key_name = get_post_custom_values($key = 'Google Play'); echo $key_name[0];
$youtube = echo $key_name = get_post_custom_values($key = 'Youtube'); echo $key_name[0];
$itunes = echo $key_name = get_post_custom_values($key = 'iTunes'); echo $key_name[0];
*/

?>

<div class="<?php echo esc_attr($sidebar_class); ?>">
    <div class="theiaStickySidebar">
        <div class="widget">
            <h5 class="widget-tile">Linkek</h5>
            <ul>
            <?php if( in_array( 'Spotify', get_post_custom_keys( '0' ) ) ) : ?>
                <li>
                    <a href="<?php echo esc_url( get_post_meta( get_the_ID(), 'Spotify', true ) ); ?>" alt="Spotify" title="Spotify" />
                        <img src="<?php echo $imguri; ?>/images/SP_10_LG.png">
                    </a>
                </li>
            <?php endif; ?>
            <?php if( in_array( 'Google Play', get_post_custom_keys( '0' ) ) ) : ?>       
                <li>
                    <a href="<?php echo esc_url( get_post_meta( get_the_ID(), 'Google Play', true ) ); ?>" alt="Google Play" title="Google Play" />
                        <img src="<?php echo $imguri; ?>/images/GP_4_LG.png">
                    </a>
                </li>
            <?php endif; ?>
            <?php if( in_array( 'Youtube', get_post_custom_keys( '0' ) ) ) : ?>
                <li>
                    <a href="<?php echo esc_url( get_post_meta( get_the_ID(), 'Youtube', true ) ); ?>" alt="Youtube" title="Youtube" />
                        <img src="<?php echo $imguri; ?>/images/youtube.png">
                    </a>
                </li>
            <?php endif; ?>
            <?php if( in_array( 'iTunes', get_post_custom_keys( '0' ) ) ) : ?>
                <li>
                    <a href="<?php echo esc_url( get_post_meta( get_the_ID(), 'iTunes', true ) ); ?>" alt="Apple Music" title="Apple Music" />
                        <img src="<?php echo $imguri; ?>/images/AM_5_LG.png">
                    </a>                
                </li>
            <?php endif; ?>
            </ul>
        </div>
    </div>
</div>

php 使单个帖子和页面标题也链接到他们的URL(有人说这对SEO有好处,但是它不能成为好的用户体验我会说......)

使单个帖子和页面标题也链接到他们的URL(有人说这对SEO有好处,但是它不能成为好的用户体验我会说......)

link-single-posts.php
add_filter( 'genesis_post_title_output', 'sg_post_title_output', 15 );
 function sg_post_title_output( $title ) {
 if ( is_singular() )
 $title = sprintf( '<a href="%s" title="%s" rel="bookmark">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), apply_filters( 'genesis_post_title_text', $title ) );
 return $title;
}  

php Wordpress入队jQuery

Wordpress入队jQuery

Enqueue-jQuery.php
  // Put this PHP code into your functions.php  le. 
  // This will load the jQuery library onto your page by inserting a link in the <head> section where you call wp_head.
  
  if(!is_admin()) {
      wp_deregister_script('jquery');
      wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/
  jquery/1.3.2/jquery.min.js"), false, '1.3.2');
      wp_enqueue_script('jquery');
  }

php transformation.php

transformation.php
<?php
namespace AppBundle\Service;
use Symfony\Component\HttpFoundation\RequestStack;
/**
 * Class ImagePathGenerator
 */
class ImagePathGenerator
{
    const LOGO_PREFIX = '/store/uploads/logo/';
    private $host;
    private $requestStack;
    /**
     * ImagePathGenerator constructor.
     * @param string       $host
     * @param RequestStack $requestStack
     */
    public function __construct($host, RequestStack $requestStack)
    {
        $this->host = $host;
        $this->requestStack = $requestStack;
    }
    /**
     * @param string $file
     * @return array
     */
    public function generateLogoSizes($file)
    {
        return $this->generateSizes(self::LOGO_PREFIX, $file);
    }
    /**
     * @param string $file
     * @return array
     */
    public function generateImagesSizes($file)
    {
        return $this->generateSizes('', $file);
    }
    protected function generateSizes($prefix, $file)
    {
        $request = $this->requestStack->getCurrentRequest();
        $template = $request->getScheme().'://'.$request->getHost().'/transform/resize_%sx-/%s';
        return [
            'small' => sprintf($template, 200, $this->host.$prefix.$file),
            'medium' => sprintf($template, 500, $this->host.$prefix.$file),
            'large' => $this->host.$prefix.$file,
        ];
    }
}