简体   繁体   中英

how to replace hyphen with blank space / white space? php

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.

$str = str_replace("-", " ", "Love-you");

now $str is "Love you";

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

You can also use explode and implode

Here is an example

$string = "Love-You";
$arr = explode("-",$string);
$string = implode(" ",$arr);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM