0

I have a PHP str_replace that replaces every hyphen - that comes right after a slash / by a non-breaking hyphen ̩.

str_replace( '/-', '/‑', $input );

I’d like to extend this str_replace with a second condition that says that also every hyphen that comes before a slash should also be replaced:

str_replace( '-/', '‑/', $input );

How can I merge these to conditions?

user1706680
  • 1,103
  • 3
  • 15
  • 34

2 Answers2

2

You can use an array of values with str_replace:

str_replace(array('/-', '-/'), array('/‑', '‑/'), $input);
cOle2
  • 4,725
  • 1
  • 24
  • 26
0

Try:

str_replace(['/-', '-/'], ['/‑', '‑/'], $input);