tags:

views:

43

answers:

3

i don't know much about PHP but these days I'm modifying an existing script. I want to know how can I replace - with white or blank space

For example a variable contains 'Love-you' and I want to replace this hyphen between them with a space like this 'Love you'.

I'll appreciate your feed back.

A: 

You can also use explode and implode

Here is an example

$string = "Love-You";
$arr = explode("-",$string);
$string = implode(" ",$arr);
Starx
This wouldn't be something I'd recommend, it's likely to use much more memory and be slower than just using str_replace().
Stephen Orr
Wow. I know that premature optimization is a bad thing, but you don't need to go this far in the other direction.
David Dorward
Guys, this is just an alternative, because you have already provided a better answer
Starx
Starx although DrColossos's tweak worked for me but I still appreciate for reading question and trying to help me. Guys keep this up. I really liked this forum.
mali
+3  A: 
$str = str_replace("-", " ", "Love-you");

now $str is "Love you";

http://php.net/manual/en/function.str-replace.php

DrColossos
Thanks DrColossosThat worked like a charm. :)
mali