$name = str_replace(' ', '_', $name);
Answer from Tim Fountain on Stack Overflow
🌐
Techareatutorials
techareatutorials.com › how-to-replace-space-with-underscore-in-php
How to Replace Space with Underscore in PHP - techareatutorials.com
<?php $str = "Hello Welcome to Tech Area"; $str = str_replace(' ','_',$str); //Replace Space with Underscore echo $str; ?>
🌐
Java2Blog
java2blog.com › home › php › replace space with underscore in php
Replace Space with Underscore in PHP [2 ways] - Java2Blog
December 5, 2022 - Use the str_replace() function to replace with underscore in PHP, for example: str_replace(" " , "_", $str). str_replaces() returns new String with old character space( ) replaced by underscore(_)
🌐
Grabthiscode
grabthiscode.com › php › php-replace-space-with-underscore
Php replace space with underscore - code example - GrabThisCode.com
php replace spaces with dash · php convert words with spaces to camelcase · php string underscore into camelcase · php insert hyphen into spaces in string · php convert spaces to underscores · php replace \n by <br> remove empty spaces php · php split string along spaces ·
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 239580 › replace-underscore-on-space
php - Replace Underscore (_) on Space ( ) - WordPress Development Stack Exchange
September 17, 2016 - Now the question: How to remove Underscore (_) in post title Tell me "where to dig"? I know that there are such a function "str_replace". Where apply it? ... $postData = array( 'post_title' => $attachment->post_title, 'post_type' => 'post', 'post_content' => $image_tag, 'post_category' => array('0'), 'post_status' => 'publish' ); P.S. I not quite understand php
🌐
SourceTrail
sourcetrail.com › home › php › solved: replace space with underscore
Solved: replace space with underscore in PHP - SourceTrail
September 19, 2023 - The function syntax includes three ... $text holds the original string, ‘Hello World’ in this case. Then we use the str_replace function to replace the spaces with underscores....
🌐
Mefancy
mefancy.com › textchange › replace-space-underscore
Replace Spaces with Underscores (and more) - Online Text Tool | MeFancy
Programming Variables: Most programming languages (Python, C, PHP) do not allow spaces in variable names. user id becomes user_id (snake_case). Data Cleaning: Standardizing data formats for database imports often requires replacing spaces with specific delimiters. Enter Text: Paste your text into the input box or drag and drop a file. Select Mode: Choose whether you want to replace spaces with underscores, hyphens, or vice versa.
Find elsewhere
🌐
Href Code
hrefcode.com › question › 12 › how-to-replace-space-with-underscore-using-php-script
how to replace space with underscore using php script?
November 17, 2021 - <?php $string = 'April 15, 2003'; $pattern = '/(\w+) (\d+), (\d+)/i'; $replacement = '${1}1,$3'; echo preg_replace($pattern, $replacement, $string); ?>
🌐
DaniWeb
daniweb.com › programming › web-development › threads › 109751 › replace-a-space-with-an-underscore-solved
php - Replace a space with an underscore SOLVED | DaniWeb
February 19, 2008 - If the goal is a URL-friendly "slug" (more than just replacing spaces), normalize the text: transliterate to ASCII, replace non-alphanumerics with underscores, collapse repeats, trim, lowercase and limit length.
🌐
Devgex
devgex.com › en › article › 00020540
Implementing Space to Underscore Replacement in PHP: Methods and Best Practices - DevGex
November 23, 2025 - PHP's built-in str_replace function is the most direct and efficient way to implement space-to-underscore replacement.
🌐
PHP Freaks
forums.phpfreaks.com › php coding › php coding help
PHP - Replace space in file name's with underscore.. - PHP Coding Help - PHP Freaks
July 11, 2009 - Hello, I have a file uploader.... I want to automatically replace any file that has been uploaded that has a space with an underscore (_) at anytime. Example: If Jerry uploaded a file called jerry file.txt, I want to be able to automatically replace it with jerry_file.txt... Any possible way of d...
🌐
Blogger
developer-paradize.blogspot.com › 2013 › 08 › how-to-replace-space-with-underscore-in.html
How to replace a space with an underscore in PHP?
July 3, 2014 - Use str_replace function of php to replace a space with an underscore. I am posting this for those of you who have struggled with this, in hopes that it just might save a couple of hours.
🌐
Webmaster World
webmasterworld.com › php › 4636762.htm
How to replace space " " with underscore " " - PHP Server Side Scripting forum at WebmasterWorld - WebmasterWorld
January 11, 2014 - So, maybe: $folder = strtolower(preg_replace("/[^A-Za-z0-9_]/g", "_", $_POST['folder'])); I just typed that up for this, so I haven't tested it for errors. Theoretically, it should replace anything other than a letter, number, or underscore ...
🌐
PHP Freaks
forums.phpfreaks.com › php coding › php coding help
Replace space with underscore character in string - PHP Coding Help - PHP Freaks
November 24, 2006 - I have a variable containing a string submitted from a form:[code]$string = ($_POST["string"]);[/code]I'm struggling to build some code that would replace any spaces in the string with the underscore character and then store back into a different variable $string2...Could anyone gi...
🌐
GitHub
gist.github.com › pbrocks › 21a1934b717e88bdf28cd04378b2d4c7
Convert capital letters to lowercase and replace spaces with underscores "_" in order to standardize usernames. · GitHub
Convert capital letters to lowercase and replace spaces with underscores "_" in order to standardize usernames. - replace-spaces-with-underscores.php