How to remove P tag from CkEditor in Laravel?

Updated at 26-Aug-2022, By samar

How to remove P tag from CkEditor in Laravel?

Hello everyone, in this post we will look at how to solve "How to remove P tag from CkEditor in Laravel?" in programming.

I am getting data from users and storing them into a database using ckeditor but I've noticed that for text, it adds `

` and `

` around the text. How can i remove this p tag after getting data from ckeditor before storing into the database in Laravel.
  • Remove <p>, </p> tag from HTML using preg_replace()

    //Get data using request
    $text = $request->ckeditor_data;
    
    $text = preg_replace("/^<p.*?>/", "",$text);
    $text = preg_replace("|</p>$|", "",$text);
    

    It will remove only <p>, </p> tags surrounding the whole text. Like if you have HTML code <p>Lorem</p><p>Ipsum</p> then it will return it will return "Lorem</p><p>Ipsum".

  • Remove all <p>, </p> tags from HTML using strip_tags()

    $input = $request->ckeditor_data;
    $data = strip_tags($input);
    

Back to code snippet queries related laravel