Debug School

rakesh kumar
rakesh kumar

Posted on

Laravel:How to remove all special characters from a string

Refer Here%3B%20%2F%2F%20Removes%20special%20chars.%20%7D)

preg_replace('/[^A-Za-z0-9\-]/', '', $string);
Enter fullscreen mode Exit fullscreen mode

Example

public function update(Request $request, $id)
    {


        log::info("mera data update aata hai");

        log::info($request);

       $typed=$request->name;
        // Replaces all spaces with hyphens.
        $res= preg_replace('/[^A-Za-z0-9\-]/', ' ', $typed); // Removes special chars.
        log::info($res);

}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)