本文整理汇总了PHP中util::str_to_bool方法的典型用法代码示例。如果您正苦于以下问题:PHP util::str_to_bool方法的具体用法?PHP util::str_to_bool怎么用?PHP util::str_to_bool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util
的用法示例。
在下文中一共展示了util::str_to_bool方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_str_to_bool
public function test_str_to_bool()
{
$this->assertTrue(util::str_to_bool('true'));
$this->assertTrue(util::str_to_bool('yes'));
$this->assertTrue(util::str_to_bool('y'));
$this->assertFalse(util::str_to_bool('false'));
$this->assertFalse(util::str_to_bool('no'));
$this->assertFalse(util::str_to_bool('n'));
}
示例2: getUri
public function getUri($title, $id = 0, $contenttypeslug, $fulluri = true)
{
$contenttype = $this->getContentType($contenttypeslug);
$tablename = $this->prefix . $contenttype['slug'];
$id = intval($id);
$fulluri = util::str_to_bool($fulluri);
$slug = makeSlug($title);
// don't allow strictly numeric slugs.
if (is_numeric($slug)) {
$slug = $contenttype['singular_slug'] . "-" . $slug;
}
// Only add 'entry/' if $full is requested.
if ($fulluri) {
$prefix = "/" . $contenttype['singular_slug'] . "/";
}
$query = "SELECT id from {$tablename} WHERE slug='{$slug}' and id!='{$id}';";
$res = $this->db->query($query)->fetch();
if (!$res) {
$uri = $prefix . $slug;
} else {
for ($i = 1; $i <= 10; $i++) {
$newslug = $slug . '-' . $i;
$query = "SELECT id from {$tablename} WHERE slug='{$newslug}' and id!='{$id}';";
$res = $this->db->query($query)->fetch();
if (!$res) {
$uri = $prefix . $newslug;
break;
}
}
// otherwise, just get a random slug.
if (empty($uri)) {
$slug = trimText($slug, 32, false, false) . "-" . makeKey(6);
$uri = $prefix . $slug;
}
}
return $uri;
}
示例3: test_str_to_bool
public function test_str_to_bool()
{
$this->assertTrue(util::str_to_bool('true'));
$this->assertTrue(util::str_to_bool('yes'));
$this->assertTrue(util::str_to_bool('y'));
$this->assertTrue(util::str_to_bool('oui'));
$this->assertTrue(util::str_to_bool('vrai'));
$this->assertFalse(util::str_to_bool('false'));
$this->assertFalse(util::str_to_bool('no'));
$this->assertFalse(util::str_to_bool('n'));
$this->assertFalse(util::str_to_bool('non'));
$this->assertFalse(util::str_to_bool('faux'));
$this->assertFalse(util::str_to_bool('test', false));
}