本文整理匯總了PHP中Str::machine方法的典型用法代碼示例。如果您正苦於以下問題:PHP Str::machine方法的具體用法?PHP Str::machine怎麽用?PHP Str::machine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Str
的用法示例。
在下文中一共展示了Str::machine方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: machineKeys
/**
* Convert keys to machine format
* @param array $array
* @param string $separator
* @return array
*/
public static function machineKeys($array, $separator = '_')
{
$keys = array_keys($array);
$keys = array_map(function ($el) use($separator) {
return Str::machine($el, $separator);
}, $keys);
return array_combine($keys, $array);
}
示例2: tably
/**
* Get a table
* @param array $records
* @return string
*/
public static function tably($records)
{
if (count($records) === 0) {
return null;
}
$htmls = array();
$htmls[] = '<table>';
foreach ($records as $record) {
$htmls[] = '<tr>';
foreach ($record as $k => $v) {
$htmls[] = sprintf('<td class="%s">%s</td>', Str::machine($k), $v);
}
$htmls[] = '</tr>';
}
$htmls[] = '</table>';
return join("\n", $htmls);
}
示例3: add_slug_to_body_class
function add_slug_to_body_class($classes = [])
{
global $post;
$file_name = basename($_SERVER['SCRIPT_FILENAME'], '.php');
$queried_object = get_queried_object();
$is_term = is_object($queried_object) && property_exists($queried_object, 'term_taxonomy_id');
if (!$is_term && !is_null($post)) {
$classes[] = $post->post_name;
} else {
$classes[] = Str::machine($file_name, '-');
}
return $classes;
}
示例4: clean
/**
* Replace non-breaking spaces with regular spaces
* @param string $input
* @return string
*/
public static function clean($input)
{
return Str::machine($input, ' ');
}
示例5: getTermsUsed
/**
* Get terms used within one post type
* Covers multiple taxonomies if applicable
* @return array
*/
public static function getTermsUsed()
{
global $wpdb;
$sql_terms = sprintf("SELECT DISTINCT\n t.term_id,\n t.name,\n t.slug,\n tt.taxonomy\n FROM %s AS t\n INNER JOIN %s AS tt ON tt.term_id = t.term_id\n INNER JOIN %s AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id\n INNER JOIN %s AS p ON p.ID = tr.object_id\n WHERE p.post_type = '%s'\n AND p.post_status = 'publish'\n ORDER BY t.name ASC", $wpdb->terms, $wpdb->term_taxonomy, $wpdb->term_relationships, $wpdb->posts, \Str::machine(get_called_class(), '-'));
return $wpdb->get_results($sql_terms, ARRAY_A);
}