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.
<?php
$str = "Paneer Pakoda dish";
echo str_replace(' ', '', $str);
?>
'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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With