Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing Spaces with Underscores

Tags:

php

People also ask

How do you change underscore spaces in Google Sheets?

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.

How do I underscore in Excel?

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");