Jump to content

PHP 5.3 -> 7 - code fix help


CreationAgent

Recommended Posts

We have a client with an older site that we haven't touched in a few years. The hosting provider is updating to PHP 7.3 mid september. From our test site there appears to be only one piece of code that needs to be updated for PHP 7.3. It's below and used to detect the initial path of the page the visitor is viewing, e.g. /educators/ or /parents/ etc.  in order to display some special links in the navigation server side include.

http://domainname.com/educators/
http://domainname.com/educators/other-url-here/
http://domainname.com/parents/other-url-parts-here/

<?php
	//GLOBAL PHP VARIABLES 

	//get current directory site path and change code links based off of that.
	class dir {
		function dir() {
			$location = $_SERVER["SCRIPT_NAME"];
			list($this->dir) = split("[a-zA-Z0-9_\-]*.php$", $location, 2);
			}
	}
	$directory = new dir();
	
	$sitepath = $directory->dir;
?>

The server error that comes back is this....

Fatal error: Uncaught Error: Call to undefined function split() in /nfs/c03/h03/mnt/46929/domains/domain-name-removed/html/includes/topnav_parents.php:9 Stack trace: #0 /nfs/c03/h03/mnt/46929/domains/domain-name-removed/html/includes/topnav_parents.php(12): dir->dir() #1 /nfs/c03/h03/mnt/46929/domains/domain-name-removed/html/parents/index.php(108): include('/nfs/c03/h03/mn...') #2 {main} thrown in /nfs/c03/h03/mnt/46929/domains/domain-name-removed/html/includes/topnav_parents.php on line 9

(I changed the site's domain name in the error message above domain-named-removed for client privacy)

We were using the $sitepath variable for some logic to display specific banner set blocks of content lower down in the footer section based on

if ($sitepath == "/parents/")  we show one set or if the $sitepath == "/educators/" we display a different set.
 

If any of you PHP 7 guys know what the issue is, please advise. I would be most grateful.   Thank you!

Link to comment
Share on other sites

This tip is taken from https://www.php.net/manual/en/function.split.php

 

 

Tip

split() is deprecated as of PHP 5.3.0. preg_split() is the suggested alternative to this function. If you don't require the power of regular expressions, it is faster to use explode(), which doesn't incur the overhead of the regular expression engine.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.