Hello Friends,
i want to allow '<br>' tags in my string not '<br />'...!
i want to also disallow '<br />'.
when i use strip_tags($string, '<br>'). in this case strip_tags also allow '<br />' tags.
Please, help me...!
Hello Friends,
i want to allow '<br>' tags in my string not '<br />'...!
i want to also disallow '<br />'.
when i use strip_tags($string, '<br>'). in this case strip_tags also allow '<br />' tags.
Please, help me...!
Quick clarification: PHP's tag stripper doesn't enforce exact tag spelling. Allowing a <br>-type tag tells PHP to keep that tag name, and many implementations treat the self-closing slash and attributes as part of the same tag, so <br />, <BR/>, or <br class="x"> can still be preserved. As hinted, a simple normalization often fixes immediate cases and confirmed that approach works — but there are safer, more robust options.
A lightweight, reliable fix (handles different spacing, case and attributes) is to replace any <br> variant with a plain <br> using a regex callback, which strips attributes and normalizes self-closing forms:
$html = preg_replace_callback(
'/<br\b[^>]*>/i',
function ($m) { return '<br>'; },
$html
); For full correctness on real HTML (and to avoid brittle regex hacks) use DOM parsing: load the HTML with DOMDocument, remove attributes from all br nodes, and unwrap or remove any other element tags while keeping their text. That approach is tolerant of nested structures and preserves textual content safely.
Notes and cautions:
These approaches let you enforce exactly one plain <br> form and remove self-closing or attribute-bearing variants while avoiding unsafe assumptions.
Jump to Post— ko ko 97str_replace('<br />','<br>',$string);Hope this help!
str_replace('<br />','<br>',$string); Hope this help!
great...! thanks dear. my problem solved.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.