【问题标题】:Quotation search online text edit for this code此代码的报价搜索在线文本编辑
【发布时间】:2018-03-08 01:38:23
【问题描述】:

这是主要的报价搜索链接: https://englishact.com/onlinequotationsearch/

这是数据库:

这是显示搜索结果的代码:

echo ucfirst(str_replace($put,$putt,$quot1[$i]['quot']))."<br><b><i> - ".ucfirst(str_replace($put,$putt,$quot1[$i]['author']))."</i></b><hr><br>";

问题

我所有的数据库数据(引号)都是小写的。所以,我尝试使用 ucfirst 将首句的字母大写。但是,多于一句话的引文就会出现问题。

举个例子:

如果您在输入框中按住报价的搜索按钮,您将获得一个报价

在你心中呆在家里。不要背诵别人的意见。我讨厌引文。告诉我你所知道的。 - 拉尔夫沃尔多爱默生

这是不正确的。应该是-

在你心中呆在家里。不要背诵别人的意见。我讨厌引用。告诉我你所知道的。 - 拉尔夫沃尔多爱默生

那么,有没有什么办法让每句话的首字母大写呢?

【问题讨论】:

标签: php


【解决方案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>";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    • 1970-01-01
    相关资源
    最近更新 更多