generate functionTue, 08 Nov 2022

get string, convert <a> tags to <div> with onclick window.open on the href attribute

function replace_html($s) { $s = preg_replace('/<a([^>]+?)>/is', '<div$1 onclick="window.open(\'$1\');">', $s); $s = str_replace('</a>', '</div>', $s); return $s; }

Questions about programming?Chat with your personal AI assistant