本文整理汇总了PHP中textlib::specialtoascii方法的典型用法代码示例。如果您正苦于以下问题:PHP textlib::specialtoascii方法的具体用法?PHP textlib::specialtoascii怎么用?PHP textlib::specialtoascii使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类textlib
的用法示例。
在下文中一共展示了textlib::specialtoascii方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read_submitted_permissions
public function read_submitted_permissions()
{
global $DB;
$this->errors = array();
// Role short name. We clean this in a special way. We want to end up
// with only lowercase safe ASCII characters.
$shortname = optional_param('shortname', null, PARAM_RAW);
if (!is_null($shortname)) {
$this->role->shortname = $shortname;
$this->role->shortname = textlib::specialtoascii($this->role->shortname);
$this->role->shortname = textlib::strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT));
if (empty($this->role->shortname)) {
$this->errors['shortname'] = get_string('errorbadroleshortname', 'role');
}
}
if ($DB->record_exists_select('role', 'shortname = ? and id <> ?', array($this->role->shortname, $this->roleid))) {
$this->errors['shortname'] = get_string('errorexistsroleshortname', 'role');
}
// Role name.
$name = optional_param('name', null, PARAM_TEXT);
if (!is_null($name)) {
$this->role->name = $name;
// Hack: short names of standard roles are equal to archetypes, empty name means localised via lang packs.
$archetypes = get_role_archetypes();
if (!isset($archetypes[$shortname]) and html_is_blank($this->role->name)) {
$this->errors['name'] = get_string('errorbadrolename', 'role');
}
}
if ($this->role->name !== '' and $DB->record_exists_select('role', 'name = ? and id <> ?', array($this->role->name, $this->roleid))) {
$this->errors['name'] = get_string('errorexistsrolename', 'role');
}
// Description.
$description = optional_param('description', null, PARAM_RAW);
if (!is_null($description)) {
$this->role->description = $description;
}
// Legacy type.
$archetype = optional_param('archetype', null, PARAM_RAW);
if (isset($archetype)) {
$archetypes = get_role_archetypes();
if (isset($archetypes[$archetype])) {
$this->role->archetype = $archetype;
} else {
$this->role->archetype = '';
}
}
// Assignable context levels.
foreach ($this->allcontextlevels as $cl => $notused) {
$assignable = optional_param('contextlevel' . $cl, null, PARAM_BOOL);
if (!is_null($assignable)) {
if ($assignable) {
$this->contextlevels[$cl] = $cl;
} else {
unset($this->contextlevels[$cl]);
}
}
}
// Now read the permissions for each capability.
parent::read_submitted_permissions();
}
示例2: mangle_pathname
/**
* Tries to convert $localname into another encoding,
* please note that it may fail really badly.
*
* @param string $localname name of file in utf-8 encoding
* @return string
*/
protected function mangle_pathname($localname)
{
if ($this->encoding === 'utf-8') {
return $localname;
}
$converted = textlib::convert($localname, 'utf-8', $this->encoding);
$original = textlib::convert($converted, $this->encoding, 'utf-8');
if ($original === $localname) {
$result = $converted;
} else {
// try ascii conversion
$converted2 = textlib::specialtoascii($localname);
$converted2 = textlib::convert($converted2, 'utf-8', $this->encoding);
$original2 = textlib::convert($converted, $this->encoding, 'utf-8');
if ($original2 === $localname) {
//this looks much better
$result = $converted2;
} else {
//bad luck - the file name may not be usable at all
$result = $converted;
}
}
$result = preg_replace('/\\.\\.+/', '', $result);
$result = ltrim($result);
// no leading /
if ($result === '.') {
$result = '';
}
return $result;
}
示例3: test_specialtoascii
/**
* Tests the static specialtoascii method
* @return void
*/
public function test_specialtoascii()
{
$str = "Žluťoučký koníček";
$this->assertSame(textlib::specialtoascii($str), 'Zlutoucky konicek');
}
示例4: foreach
if ($roles_in_file = roles_migration_get_incoming_roles()) {
foreach ($roles_in_file as $role) {
if (!isset($actions[$role->shortname])) {
echo '<p>', get_string('role_ignored', 'report_rolesmigration', $role), '</p>';
continue;
}
switch ($actions[$role->shortname]) {
case 'skip':
echo '<p>', get_string('role_ignored', 'report_rolesmigration', $role), '</p>';
break;
case 'create':
if (!array_key_exists($role->shortname, $roles['create'])) {
print_error('new_shortname_undefined');
}
$new_role_shortname = textlib::specialtoascii($roles['create'][$role->shortname]['shortname']);
$new_role_shortname = textlib::strtolower(clean_param($new_role_shortname, PARAM_ALPHANUMEXT));
$new_role_name = $roles['create'][$role->shortname]['name'];
// Code to make new role name/short name if same role name or shortname exists
$fullname = $new_role_name;
$shortname = $new_role_shortname;
$currentfullname = "";
$currentshortname = "";
$counter = 0;
do {
if ($counter) {
$suffixfull = " ".get_string("copyasnoun")." ".$counter;
$suffixshort = "_".$counter;
} else {