使用preg_replace将一个字符的多个实例转换为只有一个(aa = a)?

I have a string, I want to convert multiple appearances of - to just one -.

I have tried preg_replace('/--+/g', '-', $string) but that simply returns nothing..

You should not use g in the pattern, and you can simplify your regular expression:

preg_replace('/-+/', '-', $string);

Backslash escapes are not required.

On http://ideone.com/IOlpv:

<?
$string = "asdfsdfd----sdfsdfs-sdf-sdf";
echo preg_replace('/-+/', '-', $string);
?>

Output:

asdfsdfd-sdfsdfs-sdf-sdf
preg_replace('/([\-]+)/', '-', $string)

Your code gives the following error:

Warning: preg_replace(): Unknown modifier 'g'

There is no g modifier. Try:

preg_replace('/--+/', '-', $string)