1

Topic: Uninitialized string offset: 0 Notice raised when attribute is empty

Hello, we encountered this issue when passing content through htmLawed:

Uninitialized string offset: 0 in /path/to/htmLawed-1.2.6.php on line X

The fix is to change htmLawed source like this

Line 594:
-   unset($a[$k]); $c[] = $k. ': '. ($v[0] != '*' ? $v. (ctype_digit($v) ? 'px' : '') : 'auto');
+   unset($a[$k]); $c[] = $k. ': '. (isset($v[0]) && $v[0] !== '*' ? $v. (ctype_digit($v) ? 'px' : '') : 'auto');

basically if we encounter a width or height attribute that is an empty string, e.g. width="" or height="" the code tries to say `$v[0]` which isn't allowed on empty strings (becomes more strict of an error in later PHP versions).

2

Re: Uninitialized string offset: 0 Notice raised when attribute is empty

Thanks for noting this issue. It is now fixed in the new release (version 1.2.7, 10 April 2022).