-3

I have to remove : from the string colon for example $chapter=Area of shape:triangle

I have already tried preg_replace('[^a-zA-Z0-9]',$chapter);

Nagama Inamdar
  • 2,851
  • 22
  • 39
  • 48

2 Answers2

1

You forgot delimiters and the second parameter of preg_replace function.

preg_replace('~[^a-zA-Z0-9]+~', '', $chapter);
pavel
  • 26,538
  • 10
  • 45
  • 61
1

Maybe I don't understand the question or I over-simplify it, but ain't it just:

str_replace(":", "", $chapter);

? This would return $chapter with all colons removed.

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
Satria
  • 315
  • 2
  • 9