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条)

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊