Hello all
I want to read sting and do some processing.
for example here is my sample string.
"this is my test string
new line"
I want to read this string and then i want to add a "-" at the end of every line, is there way to do this?
result should be like this:
"this is my test string-new line"
thank you
dizyn
string problem
Moderator: General Moderators
- Jaxolotl
- Forum Contributor
- Posts: 137
- Joined: Mon Nov 13, 2006 4:19 am
- Location: Argentina and Italy
Re: string problem
The most simple thing you may use is the function str_replace()
but you may use a lot of functions and then combine them as you need, it depends on the complexity of the process you need to do
see the manual
# preg_ replace_ callback()
# preg_ replace()
# preg_ split()
# ereg_ replace()
# eregi_ replace()
# str_replace()
# str_ireplace()
# explode() then combined with implode()
Code: Select all
$original_string = "this is my test string
new line";
$processed_string = str_replace("\n","-",$original_string);
see the manual
# preg_ replace_ callback()
# preg_ replace()
# preg_ split()
# ereg_ replace()
# eregi_ replace()
# str_replace()
# str_ireplace()
# explode() then combined with implode()
Re: string problem
You may want to normalize newlines before doing a str_replace on "\n".
Code: Select all
$str = str_replace(array("\r\n", "\r"), "\n", $str);