How to Remove Underscore from String in PHP?
Sep 15, 2022
Hi Dev,
This example is focused on how to remove underscore from string in php?. you will learn remove underscore from string in php example. This article goes in detailed on php remove underscore from string. This tutorial will give you simple example of underscore remove from string in php. Alright, let’s dive into the steps.
There ara two ways to remove underscore from string in php. in the first example, we will use to str_replace() function and preg_replace() function use to remove underscore.Let's see both examples with output.
Example 1:
index.php
<?php
$str = "_Nice_nippets_.com_";
// Remove All Underscore from String
$result = str_replace("_", '', $str);
echo $result;
?>
Output:
Nicenippets.com
Example 2:
index.php
<?php
$str = "_My_webtuts_.com_";
// Remove All Underscore from String
$result = preg_replace("/_/i", '', $str);
echo $result;
?>
Output:
Mywebtuts.com
I hope it could help you...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example