Add wordpress post to categories using php code by examples

To add a post to wordpress categories by php programming, you can do like this:

Step 1. Load the WordPress environment

<?php
$inc = "E:\\xampp\\htdocs\\www.programmingbyexamples.com\\wp-load.php";
require_once($wordpress_inc_path);
?>

Step 2. Add a post to wordpress categories

Before adding, you must be sure that these categories exist and know their category id, if these categories do not exist, you will can not bind them.

<?php
$post_id=1;
$post_cats=array(8,9);
$result = wp_set_post_terms( $post_id, $terms = $post_cats, $taxonomy = 'category', $append = false );
print_r($result);
?>

Code above add post,which id = 1, to categories, their id = 8 and 9

Apply .sty file in LaTex by examples

If you have download a .sty file which named emnlp2018.sty, how to use it?

Step 1: Create a new latex document

You can create a new latex document in path:d:\latex-document

Step 2: Copy emnlp2018.sty to d:\latex-document

You can copy this .sty file to the same folder of the document you created

Step 3: Use \usepackage command in your document

like this:

\documentclass{article}
\usepackage{emnlp2018}
.....

Step 4: Complie your document

If you met problem:! LaTeX Error: File `emnlp2018.sty’ not found. Please check step 2.

Fix python theano.tensor.argmax() return argmax by examples

Consider python source code below:

import theano
import theano.tensor as T
import numpy

share_x = theano.shared(value = numpy.array([[1,2,3],[2,2,4]]), name = "x")

y = T.argmax(share_x)

print y

You can get output:argmax, not the index of the max number, why?

To theano function theano.tensor.argmax(), the input variable must be a Theano TensorVariable type, this function describes a computational graph, so you can not get index.

To use this function correctly, you can use theano.function() and read:

Learn python theano.tensor.argmax() by examples

Learn python theano.tensor.argmax() by examples

Description:

theano.tensor.argmax(x, axis=None, keepdims=False)

return the index of the maximum value along a given axis

Parameters:

x: a Theano TensorVariable type
axis: axis along which to compute the index of the maximum

Examples:

1.Get the max number Index in a maxtix

import theano
import theano.tenser as T
import numpy

Define a matrix

matrix_x = T.dmatrix()

max_index = T.argmax(matrix_x)

get_max_index = theano.function([matrix_x], max_index)

matrix_input = numpy.asarray([[1, 2, 3],[2, 2, 4]])

print get_max_index(matrix_input)

output:5

If you want to get max number index by row, you shoud edit T.argmax

max_index = T.argmax(matrix_x, axis= 1)
get_max_index = theano.function([matrix_x], max_index)

matrix_input = numpy.asarray([[1, 2, 3],[2, 2, 4]])

print get_max_index(matrix_input)

output:[2, 2]

Detect and remove any url from string using php by examples

To remove any website url in a string, you must know how to detect them, and then can remove.
Consider this string:
“M A N N I N G Mark Fisher Jonas Partner Marius Bogoevici Iwein Fuld FOREWORD BY Rod Johnson IN ACTION https://www.freeaibook.com Spring Integration in Action www.freeaibook.com www.programmingbyexamples.com Spring Integration in Action MARK FISHER JONAS PARTNER MARIUS BOGOEVICI”
There are three website urls:
https://www.freeaibook.com

www.freeaibook.com

www.programmingbyexamples.com
or any other website urls.

Examples:

1.Detect and remove any url from string using php

function removeURLS($str=""){

//$str="M A N N I N G Mark Fisher Jonas Partner Marius Bogoevici Iwein Fuld FOREWORD BY Rod Johnson IN ACTION https://www.freeaibook.com Spring Integration in Action www.freeaibook.com www.programmingbyexamples.com Spring Integration in Action MARK FISHER JONAS PARTNER MARIUS BOGOEVICI";

$tag='@(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))@';

preg_match_all($tag,$str,$r);

//print_r($r);

if(isset($r[1])){

$urls=$r[1];

$len=count($urls);

for($i=0;$i<$len;$i++){

$u=$urls[$i];

if($u!=""){

$str=str_ireplace($u,'',$str);

}

}

}

return $str;

}

Learn php array array_slice() by examples

Description:

array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = FALSE ]] )

Get a slice of the array by offset and length

Parameters:

$offset:
Offset in the array, If offset is negative, the sequence will start that far from the end of the array

$length:
The number of slice

Examples:

1.Get a slice of a array

<?php
$arr = array(1,3,4,5,5)
$result = array_slice($arr, 0, 4);
print_r($result);
?>

Test python variable value is True or False by examples

Description:

To test a variable value is True or False, you should know what value in python is False.

Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean
operations below. The following values are considered false:

• None
• False
• zero of any numeric type, for example, 0, 0L, 0.0, 0j.
• any empty sequence, for example, ”, (), [].
• any empty mapping, for example, {}.
• instances of user-defined classes, if the class defines a __nonzero__() or __len__() method, when that method returns the integer zero or bool value False.

Examples:

1.Test an list is empty or not

If no any elements in a list, it is empty

Define an empty list

>>> empty_list = []
>>> bool(empty_list)
False

Define a none empty list

>>> list = [1, 2, 3]
>>> bool(list)
True

Learn python int() by examples

Description:

class int(x=0)
class int(x, base=10)

Get an integer object constructed from a number or string x, or return 0 if no arguments are given

Parameters:

x: an integer or string

Examples:

1.Convert an integer string to an integer

if no arguments, it return 0.

>>> int()
0
>>> int('45')
45

2.Convert hexadecimal string to integer

>>> int('0x10',16)
16

How to get hexadecimal string of an integer?

Learn python hex() by examples