2018년 12월 19일 수요일

preg_replace /e to preg_replace_callback

$onAttributes = array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavaible', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragdrop', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterupdate', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmoveout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
/*
 * Bridge Light code 2018-12-19
 * PHP7에서는 preg_replace() 첫번째 인수에서 /e가 폐기 되었으므로 대체 코드 투입: line 45~47 대신 line 48~56
 */
// $str = preg_replace('/<(.*?)>/ie',
// "'<' . preg_replace(array('/javascript:[^\"\']*/i', '/(" . implode('|', $onAttributes) . ")[ \\t\\n]*=/i', '/\s+/'), array('', '', ' '), stripslashes('\\1')) . '>'",
// $str);
$str = preg_replace_callback(
'/<(.*?)>/i',
function($matches) use ($onAttributes) {
return preg_replace(
array('/javascript:[^"\']*/i', '/('.implode('|', $onAttributes) . ')[ \\t\\n]*=/i', '/\s+/'),
array('', '', ' '),
stripslashes($matches[0]));
},
$str);


kimsq ver.1.2.2 (update 20140407)
file: _core/function/lib/getContent.lib.php

LIB_getContents() 함수에서 preg_replace()를 /e 지시자 때문에 preg_replace_callback으로 대체함.

preg_replace & preg_replace_callback, understood!


Xubuntu: Installing a Printer (Canon G3060 PIXMA)

$ sudo apt install system-config-printer Download the proper driver for linux from Canon website. Turn on the printer and set up its WiFi. C...