-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,813
  • 22
  • 39
  • 47

2 Answers2

1

You forgot delimiters and the second parameter of preg_replace function.

preg_replace('~[^a-zA-Z0-9]+~', '', $chapter);
pavel
  • 25,361
  • 10
  • 41
  • 58
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
  • 166,785
  • 24
  • 204
  • 249
Satria
  • 305
  • 2
  • 9