Dev0ps's avatar

Replace hyphen (-) with space( ) in php

$string = "Within 3 days of-death the enzymes-that once-digested your-dinner begin to eat-you.";
        $string = str_replace("‐"," ",$string);
        echo $string;

not working

working in normal case but not with words

0 likes
2 replies
Dev0ps's avatar

solves by

$arr = explode("-",$string);
       echo $string = implode(" ",$arr);
Snapey's avatar

It DOES work.

Your $string = str_replace("‐"," ",$string);is not using a regular dash character so it does not match

"‐"

versus

"-"

You can see the difference ;-)

Tinker;

    >>> $string = "Within 3 days of-death the enzymes-that once-digested your-dinner begin to eat-you.";
    => "Within 3 days of-death the enzymes-that once-digested your-dinner begin to eat-you."
    >>> str_replace("-"," ",$string)
    => "Within 3 days of death the enzymes that once digested your dinner begin to eat you."
    >>> 

Please or to participate in this conversation.