In this tutorial we will see How To Replace Space With Underscore in PHP. PHP str_replace() Function can be used to replace the space with underscore in PHP.
Table of Contents
PHP str_replace() Function
PHP str_replace() Function replaces given characters or a string with other string or characters.
In this example str_replace() function is used to replace the space with underscore.
<?php
$string = "Learn PHP at HowToCodeSchool.com";
$string = str_replace(' ', '_', $string);
echo $string;
?>
In above code of PHP, space is replaced with underscore.
More PHP Replace Tutorial:
Replace Space With Dash in PHPReplace Space With in PHP
Replace Dash With Space in PHP
Replace Underscore With Space in PHP
Replace Double Quotes With Single Quotes in PHP
Replace Single Quotes With Double Quotes in PHP