本文整理汇总了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);
}