Hi
When we what to do things like
I have a string like
Or "this_is_my_string"
I want to Replace white Space or Space or " " from text in php
or just replace white space with underscore ??
or replace any Special character from text
How can i do that?
Answer is
For just spaces, use str_replace:
Syntax:
str_replace('Character to replace' ,'Replace by','Source String');
preg_replace('Character to replace' ,'Replace by','Source String');
When we what to do things like
I have a string like
$string = "this is my string";
the output should be "thisismystring"
orOr "this_is_my_string"
I want to Replace white Space or Space or " " from text in php
or just replace white space with underscore ??
or replace any Special character from text
How can i do that?
Answer is
For just spaces, use str_replace:
Syntax:
str_replace('Character to replace' ,'Replace by','Source String');
$string = str_replace(' ', '', $string);
For all whitespace, use preg_replace:preg_replace('Character to replace' ,'Replace by','Source String');
/\s+/ used for all type White Space;
$string = preg_replace('/\s+/', '', $string);
No comments:
Post a Comment
Please leave your comments and we will be reply you back ASAP
vikas agrawal