Rich-text formatting in PHP: HTML, Markdown, rich-text editors like TinyMCE and doing it securely

Поделиться
HTML-код
  • Опубликовано: 6 июн 2024
  • PHP for Beginners course: ➤ davehollingworth.net/phpy
    PHP MVC course: ► davehollingworth.net/phpmvcy
    CodeIgniter 4 course: ► davehollingworth.net/codeigni...
    In an HTML form, a textarea element is used to collect a sizeable amount of text. You can enter more text than a regular text input, but it's still just plain text. In this video we'll look at how to allow the user of a form to add formatting to the content. We'll also learn how to do it securely to avoid code injection. We'll look at using HTML directly, using a plain-text markup language like Markdown, and using a rich-text editor in the browser like TinyMCE.
    Resources:
    daringfireball.net/projects/m...
    packagist.org/packages/erusev...
    www.tiny.cloud/
    www.php.net/manual/en/functio...
    htmlpurifier.org/
    Code shown in the video:
    gist.github.com/daveh/b93ca07...
    00:00 Intro
    01:13 Allowing HTML
    02:38 Markdown
    05:52 Rich-text editors
    10:28 Using strip_tags
    12:46 Using HTMLPurifier
    16:29 Summary
  • НаукаНаука

Комментарии • 27

  • @edwardbabatunde
    @edwardbabatunde 3 месяца назад

    Straight to the point. Very impressive. Thanks for sharing

  • @ShubhamMishra-uw9yi
    @ShubhamMishra-uw9yi 3 года назад +3

    You are born to be a teacher 🙏

  • @SAIEN333
    @SAIEN333 3 месяца назад +1

    thank you, this was very easy to understand

  • @lianna5483
    @lianna5483 3 года назад +3

    Thank you very much for this video ! It's cristal clear !

  • @savanaassasinandy716
    @savanaassasinandy716 Год назад +1

    Thank you a million times over!!

  • @belowsurfacemedia
    @belowsurfacemedia Год назад

    love this! most relaxed tutorial ever :D

  • @itsHan
    @itsHan 2 года назад +1

    Thanks alot sir you really deserve 1m+ subs

  • @malekfarag5134
    @malekfarag5134 3 года назад +3

    This is awesome omg

  • @yazilimci_adam
    @yazilimci_adam Год назад +1

    Thank you very much boss.

  • @ademineshat
    @ademineshat 3 года назад

    Nice one 👌

  • @MT-ox3gz
    @MT-ox3gz 2 года назад +1

    Thank you very much

  • @giantjam4918
    @giantjam4918 3 года назад +3

    I was searching for adding this feature , thank you so much , Cant i add it using html and css only ? For adding it in an onion service ?

    • @dave-hollingworth
      @dave-hollingworth  3 года назад +1

      You can use markdown with HTML only in the browser, but you do need to have a markdown parser on the server to process it into HTML. If you want a rich-text editor like TinyMCE, then I'm not aware of any that don't use JavaScript I'm afraid.

    • @giantjam4918
      @giantjam4918 3 года назад +1

      @@dave-hollingworth thank you brilliant

  • @g7k993
    @g7k993 3 года назад

    Hey Dave thank you for the video. Quick question that’s bugging me, what’s the difference between htmlspecialchars(), htmlentities and the html purifier you’ve used?
    Future video ideas: I’m not sure if you have any small crud app in your playlist ( binge watching it rn).
    For example: “ Hotel booking system, car rental crud app or restaurant online ordering ) simple page with just a table, search form and a picture to explain how crud works. The secrete being “real life application”. That sort of videos appeal to many different audience.

    • @dave-hollingworth
      @dave-hollingworth  3 года назад

      Basically htmlspecialchars is for when you want to escape something to display it in HTML. HTML purifier is used to remove unwanted tags and attributes completely. There's a good description here: learnwebtutorials.com/difference-between-htmlentities-and-htmlspecialchars-in-php
      I don't have a CRUD series right now but that's a good idea, I'll make a note of it!

  • @sumanparajuli229
    @sumanparajuli229 3 года назад +2

    Sir create a video on.. medication tracker and notification on given timeframe with php...

    • @dave-hollingworth
      @dave-hollingworth  3 года назад

      Always looking for video ideas - please could you be a bit more specific? I tend to prefer videos that explain a single topic, so for example "how to send notifications using SMS" for example. If you can suggest simple topics like that I'll be happy to consider a video on it! Thanks

  • @pablokaram6342
    @pablokaram6342 2 года назад

    Hi Dave!, im using twig and i notice that automatically resolve the issue with the HTML special chars, (with the | raw) incidator actived, however if i change the style attribute directly in the strong tag, it doesn't purify and appears red, my question is, how can i use the purifier library with twig, of it exists some solution with the twig templates?

    • @dave-hollingworth
      @dave-hollingworth  2 года назад

      There's a package here that might help: github.com/Exercise/HTMLPurifierBundle

  • @BlueDolphinBlues
    @BlueDolphinBlues Год назад

    Thanks, this is very helpful. What about stripping php?

    • @dave-hollingworth
      @dave-hollingworth  Год назад

      Any PHP code wouldn't be executed as it would be sent to the browser - you could strip it using a regular expression though if you wanted

    • @BlueDolphinBlues
      @BlueDolphinBlues Год назад

      @@dave-hollingworth in my application the posted data would be stored and then presented as a blog. I want to give the user some ability to script without allowing them to return any session variables or information about the host.

    • @dave-hollingworth
      @dave-hollingworth  Год назад

      @@BlueDolphinBlues I'd be hesitant about giving the user script abilities - you'd have to parse the code to make sure there wasn't anything unexpected in there, which I think would be very difficult to make sure it was safe. I'm not aware of any parsers like the HTML one that allow you to strip code from PHP code. Alternatively, you could use a templating engine like Twig or something like Markdown that allow additional functionality but don't expose PHP to the user.

    • @BlueDolphinBlues
      @BlueDolphinBlues Год назад +1

      @@dave-hollingworth I completely agree.

  • @kribo9604
    @kribo9604 Год назад

    Why composer ???

    • @dave-hollingworth
      @dave-hollingworth  Год назад +1

      Composer is the easiest way to install third-party packages and their dependencies into a PHP project