dongyumiao5210 2015-03-21 21:52
浏览 19

php变量上的htmlspecialchars行为

I do know that htmlspecialchars should only be used to output to screen.But I'm having some trouble to understand it behavior of escaping malicious data.

When I print PHP variable that contains htmlspecialchars used data is escape properly.But when I use that variable inside another variable,and print the second variable,it doesn't escape special characters.

Please look at the code for better understanding

does escape

$page_owner.="<div id='pg_owner_$userx' class='now'><div id='user_img_holder' ><img src='account/".htmlspecialchars($userx)."/".htmlspecialchars($image)."' id='user_img' ><div id=''><b>".htmlspecialchars($busi_title)."</b></div></div></div>";
echo $page_owner;

doesn't escape

$all.="<div class='hold_indi_samesrc'>".$page_owner.".<div style='float:left;'>".$alu."</div></div>";
echo $all;

when I echo $all,it doesn't escape special character that is in $page_owner.

Why is it happening?Is there any way to work around with this issue?

Edit

second code block contain $page_owner which is in first code block.

When I echo $page_owner(for testing purpose),I get $userx,$busi_title 's specialchars escaped.But as I need to have $alu and $page_owner inside $all.When I echo $all,I cannot get $userx,$image,$busi_title 's special characters escaped.Is it even possible.How can I do that?

Please help,if you can.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?