StepCoding

Removing HTML tags

อ่าน [824] หมวดหมู่: Encoding และ Escaping

Removing HTML tags ก็คือการตัดส่วนที่เป็น HTML tags ออกจาก string ด้วยฟังก์ชัน strip_tags() เช่น

<?php
$input = '<p>Howdy, &quot;Cowboy&guot;</p>';
$output = strip_tags($input);
// $output = 'Howy, &quot;Cowboy&quot;'
?>

ในฟังก์ชันนี้เราอาจจะกำหนด tags ที่ไม่ต้องการให้มันตัดออก (strip) ได้โดยการกำหนดแท็กนั้น ๆ ในพารามิเตอร์ตัวที่สอง เช่น

<?php
$input = 'The <b>bold</b> tags will <i>stay</i><p>';
$output = strip_tags($input, '<b>');
// $output = 'The <b>bold</b> tags will stay'
?>

ผู้สนับสนุน