doume5227 2018-03-07 17:24
浏览 17
已采纳

报价搜索此代码的在线文本编辑

This is the main quotation search link: https://englishact.com/onlinequotationsearch/

This is the database: enter image description here

This is the code to display search result:

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

Problem

All my database data (quots) are lowercase. So, I tried to use ucfirst to make initial sentence's letter uppercase. But problem is arising for quotations with more than one sentence.

For an example:

If you press search button keeping quotation in the input box you will get one quotation

Stay at home in your mind. don't recite other people's opinions. i hate quotations. tell me what you know. - Ralph Waldo Emerson

Which is incorrect. It should be -

Stay at home in your mind. Don't recite other people's opinions. I hate quotations. Tell me what you know. - Ralph Waldo Emerson

So, is there any way to capitalize beginning letters of every sentences?

  • 写回答

1条回答 默认 最新

  • dpjo15650 2018-03-07 17:33
    关注
        $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>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用