Sunday 3 April 2016

How can I replace whitespace with underscores in php?

The \s character class will match whitespace characters. I've added the + quantifier to collapse multiple whitespace to one _. If you don't want that, remove the +

$picture =preg_replace('/\s+/', '_', uniqid()."_".$image_name);

1 comment:

  1. Simple and crispy, which effectively helps a lot. Thank you very much for the sharing of this code.

    Namakkal martjack | best e-commerce service provider

    ReplyDelete

Thank You For Comment