Skip to content

Instantly share code, notes, and snippets.

View NorihikoMoriyama's full-sized avatar

NorihikoMoriyama NorihikoMoriyama

View GitHub Profile
@NorihikoMoriyama
NorihikoMoriyama / atagitaiwohsc.php
Last active May 14, 2023 09:21 — forked from oh-sky/atagitaiwohsc.php
PHPで <a> タグ以外をhtmlspecialcharsする関数
<?php
// <a> </a> タグ以外をhtmlspecialcharsする関数
function atagigaiwohsc($src,$flags = ENT_QUOTES){
// encode including <a></a>
$sanitized = htmlspecialchars($src,$flags);
// decode all <a>
if(preg_match_all('@&lt;a.*?&gt;@', $sanitized, $matches, PREG_SET_ORDER)){
foreach($matches as $match){