dsfb20227 2016-01-12 04:51 采纳率: 0%
浏览 67
已采纳

删除PHP中两个单词之间的空格[复制]

This question already has an answer here:

I am developing a website in PHP. In it, I am saving the images in a folder on a server.

I accept a name from user and want to use that name as the image name. Sometimes the user enters a name like two words.

So I want to remove the space between two words. For example, if the user enters as 'Paneer Pakoda dish', I want to convert it like 'PaneerPakodaDish'.

How can I do that?

I used

1) str_replace(' ', '', $str);

2) preg_replace(' ', '', $str);

3) trim($str, ' ');

But these are not giving the output as I required.

</div>
  • 写回答

6条回答 默认 最新

  • douhao8456 2016-01-12 05:34
    关注

    'PaneerPakodaDish' should be the desired output.

    $string = 'Paneer Pakoda dish';
    $s = ucfirst($string);
    $bar = ucwords(strtolower($s));
    echo $data = preg_replace('/\s+/', '', $bar);
    

    It will give you the exact output 'PaneerPakodaDish' where character "D" will also be in capital.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探