【发布时间】:2021-04-05 17:15:29
【问题描述】:
我得到一个城市名称作为 GET 变量。我需要将第一个字母大写。 如果 Get 变量是“herning”,我可以毫无问题地将其设为 H,但如果变量是“ølstykke”,我只能将其设为小写 ø,而不是大写 Ø。
header('Content-type: text/html; charset=utf-8');
print strToUpper(mb_substr($_GET["city"], 0, 1));
如果我不将标头设置为 utf-8,我只会得到奇怪的字符。
有什么想法吗?
更新代码
<?php
header('Content-type: text/html; charset=utf-8');
$city = mb_convert_case($_GET["city"], MB_CASE_TITLE, "UTF-8");//Ølstykke
print $city;
$section = file_get_contents('https://api.dataforsyningen.dk/steder?hovedtype=Bebyggelse&undertype=by&prim%C3%A6rtnavn='.$city);
$section = json_decode($section);
print '<pre>';
print_r($section);
print '</pre>';
解决方案:发送到 dataforsyningen 时,围绕 $city 的 urlencode() 完成了这项工作。
【问题讨论】: