How to remove P tag from CkEditor in Laravel?

Created 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 `<p>` and `</p>` 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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.