Deprecated: Function … is deprecated in PHP

Symptom:

Shows errors like below on your Joomla, Drupal or in any other php coded webpage.

  • Deprecated: Function ereg() is deprecated in …
  • Deprecated: Function split() is deprecated in …
  • Deprecated: Function set_magic_quotes_runtime() in …
  • …will add more…Please let me know if you find more.

Reason:

Those functions got replaced with alternate ones. (Sorry that I don’t know the reason behind that. May be the new ones might have some new features). Also I experienced this problem after upgrading PHP engine on my server.

Fix:

ereg() fix:

FTP the web server and open the file showing error, search for “ereg” and replace ereg(…) with mb_ereg(…). The syntax is same for both. (Try this and keep it if it works. It will work 90% sure.)

split() fix:

FTP the web server and open the file showing error, search for “split” and replace split(…) with explode(…). (Same as above.)

set_magic_quotes_runtime() fix:

Replace the below line showing error

set_magic_quotes_runtime(0);

with below code

// Check if magic_quotes_runtime is active
if(get_magic_quotes_runtime())
{
// Deactivate
set_magic_quotes_runtime(false);
}

Note: More findings will be added to this post as and when I experience them. Please comment below if you had experienced and fixed any other deprecations.

Tip: Display unicode data from mySQL DB on a website in PHP.

Before we start we need to make mySQL database capable of supporting unicode characters. For that we need to change the database collation or the table collation to utf8_unicode_ci. This can be done with phpmyadmin portal.

  1. Click the table you need to change.
  2. select Structure tab.
  3. Check the required column and click change or edit.
  4. From the collation drop down select utf8_unicode_ci.
  5. Press Go.

Click here to read more