$name = str_replace(' ', '_', $name);
Answer from Tim Fountain on Stack Overflow Top answer 1 of 4
209
I'll suggest that you use this as it will check for both single and multiple occurrence of white space (as suggested by Lucas Green).
$journalName = preg_replace('/\s+/', '_', $journalName);
instead of:
$journalName = str_replace(' ', '_', $journalName);
2 of 4
23
Try this instead:
$journalName = preg_replace('/\s+/', '_', $journalName);
Explanation: you are most likely seeing whitespace, not just plain spaces (there is a difference).
IQCode
iqcode.com › code › php › php-replace-space-with-underscore
php replace space with underscore Code Example
October 7, 2021 - $str = str_replace(' ', '_', $str);
Stack Exchange
wordpress.stackexchange.com › questions › 239580 › replace-underscore-on-space
php - Replace Underscore (_) on Space ( ) - WordPress Development Stack Exchange
September 17, 2016 - I use the plugin "Auto Post With Image Upload" For example I load an image with name "Image_Name" then plugin creates a post with name "Image_Name" 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? Here is a piece of code: $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 ·
SitePoint
sitepoint.com › php
How to replace space " " with underscore "_" - PHP - SitePoint Forums | Web Development & Design Community
January 11, 2014 - I need a little help. I have created the below script. A form that save its info to my database and a long with that it create some (2 on different paths) folders on the server. My issue is that in the form under ”folder” you can type the name of the folder you want to create along with ...
Grabthiscode
grabthiscode.com › php › php-replace-space-with-underscore
Php replace space with underscore - code example - GrabThisCode.com
Get code examples like"php replace space with underscore". Write more code and save time using our ready-made code examples.
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...
Laracasts
laracasts.com › discuss › channels › general-discussion › convert-space-to-underscore
Convert <space> to <underscore>
The most popular Laravel and PHP programming forum.
Top answer 1 of 4
42
You can use the array_map function.
function modify($str) {
return ucwords(str_replace("_", " ", $str));
}
Then in just use the above function as follows:
$states=array_map("modify", $old_states)
2 of 4
4
Need to use array_map function like as
$state = array("gujarat","andhra_pradesh","madhya_pradesh","uttar_pradesh");
$state = array_map(upper, $state);
function upper($state){
return str_replace('_', ' ', ucwords($state));
}
print_r($state);// output Array ( [0] => Gujarat [1] => Andhra pradesh [2] => Madhya pradesh [3] => Uttar pradesh )
Top answer 1 of 3
7
use the str_replace() function:
<?php
$old = 'OMG_This_Is_A_One_Stupid_Error';
$new = str_replace(' ', '_', $old);
echo $old; // will output OMG This Is A One Stupid error
?>
Reverse the parameters to obtain the reverse effect
<?php
$old = 'OMG This Is A One Stupid_Error';
$new = str_replace('_', ' ', $old);
echo $old; // will output OMG_This_Is_A_One_Stupid error
?>
2 of 3
1
Allow me to introduce you to str_replace()
$var = str_replace(' ', '_', $var);
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; ?>
Snipplr
snipplr.com › view › 19793 › how-to-replace-spaces-in-a-file-name-with-underscores
How to replace spaces in a file name with underscores - PHP Snipplr Social Repository
How to access a JSON in PHP easy (like a JSON recordset with multiple fields) 2627 · How to replace the default WordPress “W†logo in the administrative header with a custom alternative · 3330 · How to read from a file in Java · 2731 · Extjs - how to select a row in a grid with a right-mouse click · 867 · Convert spaces in file names to underscores ·
Savecode
savecode.net › code › php › php+replace+space+with+underscore
php replace space with underscore - SaveCode.net
July 13, 2020 - $str = str_replace(' ', '_', $str);