6

I want to replace the horizontal ellipse (…) with three period (...)in a given string.
Till now I have tried are:

str_replace('…','...', $text);
str_replace('…', '...', $text);
str_replace('&hellips', '...', $text);

But not able to get the desired output. Can you please suggest some method for it.

EDIT:
One more problem I am facing related to this is when I paste the ~…~u character in my editor (I am using Editplus). the ... are converted into a rectangle. (see screenshot). enter image description here

Thanks

jimy
  • 4,848
  • 3
  • 35
  • 52
  • The first will work, but you need to instruct your editor that the file is UTF-8. This will also fix the "edit" problem. – Jon May 20 '13 at 10:06
  • @Jon My editor encoding is already UTF-8 – jimy May 20 '13 at 10:07
  • Your first method [should work fine](http://3v4l.org/Q4p51). I'd say that you are simply guessing what that char is from a visual inspection of the HTML-rendered view. Additionally, I'm curious about why you think you need to remove that char. – Álvaro González May 20 '13 at 10:09
  • @ÁlvaroG.Vicario for the reason of not working see my edit part of question. The reason I want to remove is that when I am processing the text I want to exempt puncutation character from it like period, comma and this ellipsis. – jimy May 20 '13 at 10:15

3 Answers3

2

try to use preg_replace with the /u modifier (the string is treated as an unicode string):

$result = preg_replace('~…~u', '...', $string);
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
2

Try This

str_replace('…', '...', htmlentities($text));
Sudz
  • 4,268
  • 2
  • 17
  • 26
  • No luck... the ellipsis is converted into some wired characters when htmlentities is applied – jimy May 20 '13 at 10:05
  • This worked for me: `str_replace('…', '', htmlentities($str));` – Portable Page Mar 15 '16 at 13:59
  • Works, but encodes all html in the string too, for example if you use this for WordPress (more…) link. `str_replace( '…', '', $str);` works to just replace the hellip sign. – RemBem Dec 24 '21 at 11:19
0

This works:

str_replace( '…', '', $str);
RemBem
  • 77
  • 1
  • 3