htmlentities කාර්යය

htmlentities කාර්යය සංකේත අනුරූප HTML සත්‍යතා වෙත පරිවර්තනය කරයි. වඩා හොඳ අවබෝධයක් සඳහා උදාහරණ බලන්න.

මෙම කාර්යය htmlspecialchars හා සමාන වේ, කෙසේවෙතත්, එයට වඩා වෙනස්ව, HTML සත්‍යතාවක් ඇති සියලුම සංකේත පරිවර්තනය කරයි.

වාක්‍ය රචනය

phphtmlentities(string $string, int $flags = ENT_COMPAT, ?string $encoding = null, bool $double_encode = true): string

උදාහරණය

ටැග් සහිත නූලක් පරිවර්තනය කරමු:

php<?php
  $str = '<b>text</b>';
  $res = htmlentities($str);
  
  echo $res;
?>

කේතය ක්‍රියාත්මක කිරීමේ ප්‍රතිඵලය:

php'<b>text</b>'

උදාහරණය

ඇම්පර්සැන්ඩ් සමඟ නූලක් පරිවර්තනය කරමු:

php<?php
  $str = 'test: &';
  $res = htmlentities($str);
  
  echo $res;
?>

කේතය ක්‍රියාත්මක කිරීමේ ප්‍රතිඵලය:

php'test: &'

මෙයද බලන්න

  • html_entity_decode කාර්යය,
    ප්‍රතිලෝම මෙහෙයුම සිදු කරයි
  • htmlspecialchars කාර්යය,
    සමාන මෙහෙයුමක් සිදු කරයි