简体   繁体   English

如何将大写url转换为小写

[英]How to convert uppercase url to lowercase

In my website, For example: 在我的网站中,例如:

**http://example.com/products/New-York/Coffee-Table/1**

to

**http://example.com/products/new-york/coffee-table/1**

PHP has a few built-in functions for converting string cases. PHP具有一些用于转换字符串大小写的内置函数。

string strtolower ( string $string )

Returns string with all alphabetic characters converted to lowercase. 返回所有字母字符均转换为小写的字符串。
Note that 'alphabetic' is determined by the current locale. 请注意,“字母顺序”由当前语言环境决定。 This means that eg in the default "C" locale, characters such as umlaut-A (Ä) will not be converted. 这意味着,例如在默认的“ C”语言环境中,诸如umlaut-A(Ä)之类的字符将不会转换。

string strtoupper ( string $string )

Returns string with all alphabetic characters converted to uppercase. 返回所有字母字符都转换为大写的字符串。
Note that 'alphabetic' is determined by the current locale. 请注意,“字母顺序”由当前语言环境决定。 For instance, in the default "C" locale characters such as umlaut-a (ä) will not be converted. 例如,在默认的“ C”区域设置字符(例如umlaut-a(ä))将不会转换。

string mb_strtolower ( string $str [, string $encoding = mb_internal_encoding() ] )

Returns str with all alphabetic characters converted to lowercase. 返回所有字母转换为小写的str。

string mb_strtoupper ( string $str [, string $encoding = mb_internal_encoding() ] )

Returns str with all alphabetic characters converted to uppercase. 返回所有已转换为大写字母的字母的str。

string mb_convert_case ( string $str , int $mode [, string $encoding = mb_internal_encoding() ] )

Performs case folding on a string, converted in the way specified by mode. 对字符串执行大小写折叠,以方式指定的方式转换。

-- -

Full documentation: http://php.net/docs.php 完整文档: http : //php.net/docs.php

You can do that in to .htaccess to force url to lowercase. 您可以在.htaccess执行此操作,以强制url为小写。 Try this to your .htaccess file : 试试这个到您的.htaccess文件:

RewriteCond $1 [A-Z]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /${lowercase:$1} [R=301,L]

Use mb_strtolower($url) . 使用mb_strtolower($url) Use strtolower($url) if you are not concerned about non-ASCII characters in the URL. 如果您不关心URL中的非ASCII字符,请使用strtolower($url) strtolower() mishandles multibyte characters. strtolower()处理多字节字符。

Please use the inbuild PHP function strtolower() to convert your string to Lowercase. 请使用内置的PHP函数strtolower()将字符串转换为小写。

$myUrl = "http://example.com/products/New-York/Coffee-Table/1";

$myModifiedUrl = strtolower($myUrl);

//$myModifiedUrl contents the string with lower case.

Hopefully you are looking for this. 希望您正在寻找这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM