这是主要的报价搜索链接: https://englishact.com/onlinequotationsearch/
这是显示搜索结果的代码:
p = ArgumentParser()
# add options
class MyNamespace:
pass
class MyDictNamespace:
# Provide __getitem__ and __setitem__ wrappers around getattr and setattr
...
p1 = p.parse_args() # Use the default Namespace class
p2 = p.parse_args(namespace=MyNamespace)
p3 = p.parse_args(namespace=MyDictNamespace)
问题
我的所有数据库数据(quots)都是小写的。所以,我尝试使用ucfirst使首字母大写的字母大写。但是,引用不止一个句子的问题就出现了。
举个例子:
如果按下搜索按钮,在输入框中保留引用,您将获得一个报价单
留在家中。不要背诵别人的意见。我讨厌报价。告诉我你所知道的。 - Ralph Waldo Emerson
哪个不对。它应该是 -
留在家中。不要背诵别人的意见。我讨厌引文。告诉我你所知道的。 - Ralph Waldo Emerson
那么,有没有办法将每个句子的开头字母大写?
答案 0 :(得分:1)
$str = $quot1[$i]['quot'];
//now capitalize every letter after a . ? and ! followed by space
$str = preg_replace_callback('/[.!?] .*?\w/',
create_function('$matches', 'return strtoupper($matches[0]);'), $str);
echo ucfirst(str_replace($put,$putt,$str))."<br><b><i> - ".ucfirst(str_replace($put,$putt,$quot1[$i]['author']))."</i></b><hr><br>";