Skip to content

Tag: php

PHP Undefined offset: 0 error in server log. How to avoid it?

I am getting the title error in my Nginx server log. I have checked the many other similarly asked questions without success. The php script works as intended but the error keeps appearing everytime the page is hit. Here’s the affected code: And the relevant function (select_record) is as follows: I&#82…

Replace all non printable characters except newline characters

I want to replace all non printable characters, especially emojis from a text but want to retain the newline characters like n and r I currently have this for escaping the non printable characters but it escapes n and r also: Answer [:print:] is a POSIX character class for printable chars. If you use it in a …

PHP: getting user’s IP address using lighttpd

I tried this function but this always return the host/website’s IP address instead of the user’s IP any idea why and how to fix it? the website is not hosted on localhost and I’m using lighttpd to host the website Answer lighttpd provides the remote address in the CGI environment variable RE…

WordPress JavaScript

I’m trying to achieve a custom option inside the “Publish Metabox” in WordPress admin custom post. And I want to know is there any native way to do expand/collapse divs (Check the below screenshot). I wonder how WordPress itself achieves it like the below screenshot? (Maybe match the IDs lik…