Replace Space With Underscore in Google SheetsSelect the range of cells where you want to replace spaces (B2:B7), and in the Menu, go to Edit > Find and replace (or use the keyboard shortcut CTRL + H). 2. In the pop-up window, (1) enter space in the Find box and (2) underscore (_) in the Replace with box.
Press CTRL+1. Under Effects, check the Superscript or Subscript box, and click OK. Tip: Although Excel doesn't have quick keyboard shortcuts to these commands, you can navigate the menus and dialogs with just the keyboard. Use Alt+HFNE for superscript, and Alt+HFNB for subscript.
$name = str_replace(' ', '_', $name);
As of others have explained how to do it using str_replace
, you can also use regex to achieve this.
$name = preg_replace('/\s+/', '_', $name);
$name = str_replace(' ', '_', $name);
http://php.net/manual/en/function.str-replace.php
Use str_replace function of PHP.
Something like:
$str = str_replace(' ', '_', $str);
Call http://php.net/str_replace: $input = str_replace(' ', '_', $input);
Use str_replace:
str_replace(" ","_","Alex Newton");
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