Help with converting piece of script from 5.6 to 7.1

Hello guys,

A while back my nephew helped me to make me a simple website using a little bit of php. But since my webhoster upgraded the server to php 7, it is showing a blank page below the header. There is only one page which uses a bit of php and that’s the index. The php is used for the menu just below the header. Luckily I can set my php back but my webhoster asked me to update the scripting. And I would normally do that, but my nephew died a year ago and I only know a bit about html. I already figured out it has something to do with “split” which is depreciated, but I couldn’t get it fixed. I am positive it is a minor change but please would somebody be so kind to help me find the culprit?

I think the problem occurs in this part of the script on my index:
[php]
<?php

	$dirPrefix = "/?p=";
	$openDir = "page";    
	
	$fileDir = opendir($openDir); 				
	$sortFiles = array(); 						
	while($sortFiles[] = readdir($fileDir)); 	
	sort($sortFiles); 							
	closedir($fileDir); 						
	
	echo '<li><a href="/">Home Page</a></li>';
	
	foreach ($sortFiles as $eachFile) {
	
	    if ($eachFile != "." && $eachFile != "..") { 
	    
	    	list($fileName, $fileExtension) = split('[/.-]', $eachFile);   
	    	$ucFileName = ucfirst($fileName);  
	    	  
	    	if($ucFileName == "Home" OR $ucFileName == "Contact" OR $ucFileName == "Examplepage" OR $ucFileName == "") { } else {
	    	  
	    		echo '<li><a href="' . $dirPrefix . $fileName . '">' . $ucFileName . '</a></li>';
	    	  
	    	}
	    
	    }
	
	}
	
	echo '<li><a href="' . $dirPrefix . 'contact">Contact</a></li>';
	
	
	?>

[/php]

Thanks in advance guys!

I see enough watched my post, but nobody responded yet. Am I asking a difficult question? Or do I need to post the whole index?

Not a tough problem, but first you have to know what kind of error(s) you are getting. Sounds like you don’t have error reporting turned on? I got that feeling from the following statement you made ->
“But since my webhoster upgraded the server to php 7, it is showing a blank page below the header.”

So turn it on by doing this at the top of the page or in a configuration file ->

[php]/* Turn on error reporting */
ini_set(‘display_errors’, 1);
ini_set(‘display_startup_errors’, 1);
error_reporting(-1); // -1 = on || 0 = off[/php]

It might help you out, if not get back with us and I’m sure someone will help you out. It’s been kind of slow here lately that is probably why you have gotten a slow reply.

Sorry didn’t read you question thoroughly -> check out the following links
http://php.net/manual/en/function.preg-split.php
http://php.net/manual/en/function.explode.php
http://php.net/manual/en/function.str-split.php
one of them should help you replacing split.

I’ll also take a better look at the script on my local server.

This might be something that might work though I couldn’t test it out exactly like you had it.
[php]$dirPrefix = “/?p=”;
$openDir = “page”;
$fileDir = opendir($openDir);
$sortFiles = array();
while ($sortFiles[] = readdir($fileDir));
sort($sortFiles);
closedir($fileDir);
$sortFiles = array_slice($sortFiles, 3);
echo ‘

  • Home Page
  • ’;
    //echo “
    ” . print_r($sortFiles, 1) . “
    \n”;
    for ($i = 0; $i < count($sortFiles); $i++) {
    $eachFile = $sortFiles[$i];
    $path_parts = pathinfo($eachFile);
    //echo “
    ” . print_r($path_parts, 1) . “
    ”;
    $ucFileName = ucfirst($path_parts[‘filename’]);
    $fileExtension = $path_parts[‘extension’];
    $fileName = $path_parts[‘basename’];
    if ($ucFileName == "Home" OR $ucFileName == "Contact" OR $ucFileName == "Examplepage" OR $ucFileName == "") {
        
    } else {
    
        echo '<li><a href="' . $dirPrefix . $fileName . '">' . $ucFileName . '</a></li>';
    }
    

    }

    echo ‘

  • Contact
  • ’;[/php]

    Here’s how I tested the script ->
    [php]<?php

    /* Turn on error reporting */
    ini_set(‘display_errors’, 1);
    ini_set(‘display_startup_errors’, 1);
    error_reporting(-1); // -1 = on || 0 = off

    $dirPrefix = “/?p=”;
    $openDir = “lib/css”;

    $fileDir = opendir($openDir);
    $sortFiles = array();
    while ($sortFiles[] = readdir($fileDir));
    sort($sortFiles);
    closedir($fileDir);
    $sortFiles = array_slice($sortFiles, 3);
    echo ‘

  • Home Page
  • ’;
    //echo “
    ” . print_r($sortFiles, 1) . “
    \n”;
    for ($i = 0; $i < count($sortFiles); $i++) {
    $eachFile = $sortFiles[$i];
    $path_parts = pathinfo($eachFile);
    //echo “
    ” . print_r($path_parts, 1) . “
    ”;
    $ucFileName = ucfirst($path_parts[‘filename’]);
    if (isset($path_parts[‘extension’])) {
    $fileExtension = $path_parts[‘extension’];
    }
    $fileName = $path_parts['basename'];
    
    
    if ($ucFileName == "Home" OR $ucFileName == "Contact" OR $ucFileName == "Examplepage" OR $ucFileName == "") {
        
    } else {
    
        echo '<li><a href="' . $dirPrefix . $fileName . '">' . $ucFileName . '</a></li>';
    }
    

    }

    echo ‘

  • Contact
  • ’;
    [/php]

    Tightening the script even further (I’m sure some egghead could even do it more) I get this:
    [php]<?php

    /* Turn on error reporting */
    ini_set(‘display_errors’, 1);
    ini_set(‘display_startup_errors’, 1);
    error_reporting(-1); // -1 = on || 0 = off

    $dirPrefix = “/?p=”;
    $openDir = “lib/css”; /* This is what you had $openDir = “page”; /
    $sortFiles = glob($openDir . "/
    .*");
    echo ‘

  • Home Page
  • ’;
    //echo “
    ” . print_r($sortFiles, 1) . “
    \n”;
    for ($i = 0; $i < count($sortFiles); $i++) {
    $eachFile = $sortFiles[$i];
    $path_parts = pathinfo($eachFile);
    //echo “
    ” . print_r($path_parts, 1) . “
    ”;
    $ucFileName = ucfirst($path_parts[‘filename’]);
    if (isset($path_parts[‘extension’])) {
    $fileExtension = $path_parts[‘extension’];
    }
    $fileName = $path_parts['basename'];
    
    
    if ($ucFileName == "Home" OR $ucFileName == "Contact" OR $ucFileName == "Examplepage" OR $ucFileName == "") {
        
    } else {
    
        echo '<li><a href="' . $dirPrefix . $fileName . '">' . $ucFileName . '</a></li>';
    }
    

    }

    echo ‘

  • Contact
  • ’;[/php]

    I am so much appreciating your help, and it seems we are almost there, but still missing a vital piece. I had to edit a small piece. I replaced “$openDir = “lib/css”;” with "$openDir = “pagina”; " to make the menu work. Since the menu pages are in the directory called “pagina”. It’s a dutch website and pagina means page.

    I will post the whole index page here so you maybe understand more what the problem is:

    [php]

    <?php if(isset($_GET["p"])) { echo ucfirst($_GET["p"]) . " - "; } ?> Title text
    <div id="topWrapper">
    	
    	<div id="top">
    		<div id="logo"><a href="/"><img src="img/logo.jpg"></a></div>
    	</div>
    	
    </div>
    
    <div id="menu">
    	
    	<ul>
    		
    	  <?php
    

    /* Turn on error reporting */
    ini_set(‘display_errors’, 1);
    ini_set(‘display_startup_errors’, 1);
    error_reporting(-1); // -1 = on || 0 = off

    $dirPrefix = “/?p=”;
    $openDir = “pagina”; /* This is what you had $openDir = “page”; /
    $sortFiles = glob($openDir . "/
    .*");
    echo ‘

  • Home
  • ’;
    //echo “
    ” . print_r($sortFiles, 1) . “
    \n”;
    for ($i = 0; $i < count($sortFiles); $i++) {
    $eachFile = $sortFiles[$i];
    $path_parts = pathinfo($eachFile);
    //echo “
    ” . print_r($path_parts, 1) . “
    ”;
    $ucFileName = ucfirst($path_parts[‘filename’]);
    if (isset($path_parts[‘extension’])) {
    $fileExtension = $path_parts[‘extension’];
    }
     $fileName = $path_parts['basename'];
    
    
     if ($ucFileName == "Home" OR $ucFileName == "Contact" OR $ucFileName == "Voorbeeldpagina" OR $ucFileName == "") {
         
     } else {
    
         echo '<li><a href="' . $dirPrefix . $fileName . '">' . $ucFileName . '</a></li>';
     }
    

    }

    echo ‘

  • Contact
  • ’;
    		?>
    		   		
    	</ul>
    	<div style="clear: both;"></div>
    	
    </div>
    
    <div id="content">
    	
    	<?php
    	
    	// GET CURRENT PAGE
    	$HUIDIGEPAGINA = $_GET["p"];
    	if($HUIDIGEPAGINA == "") {
    	
    		include("pagina/home.html");
    	
    	} else {
    	
    		include("pagina/" . $HUIDIGEPAGINA . ".html");
    	
    	}
    	
    	?>
    
    </div>
    
    <div id="push"></div>
    
    Copyright - <?php echo date("Y"); ?>
    [/php]

    And the error I get now is: Undefined index: p in index.php on line 80

    I think modifying the code to this might help?

    [php]if (isset($_GET[“p”])) {
    // GET CURRENT PAGE
    $HUIDIGEPAGINA = $_GET[“p”];
    if ($HUIDIGEPAGINA == “”) {

        include("pagina/home.html");
    } else {
    
        include("pagina/" . $HUIDIGEPAGINA . ".html");
    }
    

    }[/php]

    Again we are getting a bit further, but not fully. The homepage is still blank below the header but now the contact page works… Although every other page gives an error like this:

    Warning: include(pagina/example.html.html): failed to open stream: No such file or directory in /home/usernameplaceholder/public_html/index.php on line 87

    Warning: include(): Failed opening ‘pagina/example.html.html’ for inclusion (include_path=’.:/opt/cpanel/ea-php70/root/usr/share/pear’) in /home/usernameplaceholder/public_html/index.php on line 87

    As you can see I get a double html after the pagename.

    I also tried this:

    [php] if (isset($_GET[“p”])) {
    // GET CURRENT PAGE
    $HUIDIGEPAGINA = $_GET[“p”];
    if ($HUIDIGEPAGINA == “”) {

          include("pagina/home.html");
      } else {
    
          include("pagina/" . $HUIDIGEPAGINA . ""); //I removed the .html
     }
    

    }[/php]

    With above code I got every other page working, except home was till blank and contact page broke because it was missing the “.html”.

    Do a

    [php]echo $_GET[“p”] . “
    ”;[/php]

    after the if statement.

    I’m guessing the only thing you’ll have to do is

    [php]include(“pagina/” . $HUIDIGEPAGINA); // That is if the echo shows up like example.html for example? [/php]

    though I think something more is going on…

    [php]if (isset($_GET[“p”])) {
    // GET CURRENT PAGE

    / * Get the current page */
    $myPage= filter_input(INPUT_SERVER, ‘PHP_SELF’, FILTER_SANITIZE_URL);
    $page_parts = pathinfo($myPage);
    $pageName = ucfirst($page_parts[‘filename’]); // Do an echo for $pageName to see what the name for Home page really is
    $HUIDIGEPAGINA = $_GET[“p”];
    if ($pageName === “Home”) { // index.html or index.php is usually the home page if this doesn’t work

            include("pagina/home.html");
        } else {
    
            include("pagina/" . $HUIDIGEPAGINA); //I removed the .html
      }
    

    }[/php]

    Ooooooh… ALMOST! :o
    Only the homepagina is given me problems (the first page when you land on the page). It is still blank below the header. Everything else works. I have now this:

    [php]

    <div id="topWrapper">
    	
    	<div id="top">
    		<div id="logo"><a href="/"><img src="img/logo.jpg"></a></div>
    	</div>
    	
    </div>
    
    <div id="menu">
    	
    	<ul>
    		
    	  <?php
    

    /* Turn on error reporting */
    ini_set(‘display_errors’, 1);
    ini_set(‘display_startup_errors’, 1);
    error_reporting(-1); // -1 = on || 0 = off

    $dirPrefix = “/?p=”;
    $openDir = “pagina”; /* This is what you had $openDir = “page”; /
    $sortFiles = glob($openDir . "/
    .*");
    echo ‘

  • Homepagina
  • ’;
    //echo “
    ” . print_r($sortFiles, 1) . “
    \n”;
    for ($i = 0; $i < count($sortFiles); $i++) {
    $eachFile = $sortFiles[$i];
    $path_parts = pathinfo($eachFile);
    //echo “
    ” . print_r($path_parts, 1) . “
    ”;
    $ucFileName = ucfirst($path_parts[‘filename’]);
    if (isset($path_parts[‘extension’])) {
    $fileExtension = $path_parts[‘extension’];
    }
     $fileName = $path_parts['basename'];
    
    
     if ($ucFileName == "Home" OR $ucFileName == "Contact" OR $ucFileName == "Voorbeeldpagina" OR $ucFileName == "") {
         
     } else {
    
         echo '<li><a href="' . $dirPrefix . $fileName . '">' . $ucFileName . '</a></li>';
     }
    

    }

    echo ‘

  • Contact
  • ’;
    		?>
    		   		
    	</ul>
    	<div style="clear: both;"></div>
    	
    </div>
    
    <div id="content">
    	
    	<?php
    	
    	 if (isset($_GET["p"])) {
    

    // GET CURRENT PAGE
    $HUIDIGEPAGINA = $_GET[“p”];
    if ($HUIDIGEPAGINA == “”) {

          include("pagina/home.html");
      } else {
    
          include("pagina/" . $HUIDIGEPAGINA);
     }
    

    }

    	?>
    
    </div>
    
    <div id="push"></div>
    
    Alle rechten voorbehouden - <?php echo date("Y"); ?>
    [/php]

    I didn’t add “echo $_GET[“p”] . “
    ”;” though because it gave an error in my dreamweaver. Maybe I didn’t add it on the right place. Place show me the full body with that so I know where it should go.

    [php] if (isset($_GET[“p”])) {
    // GET CURRENT PAGE
    echo $_GET[“p”] . “
    ”;
    / * Get the current page */
    $myPage= filter_input(INPUT_SERVER, ‘PHP_SELF’, FILTER_SANITIZE_URL);
    $page_parts = pathinfo($myPage);
    $pageName = ucfirst($page_parts[‘filename’]); // Do an echo for $pageName to see what the name for Home page really is
    echo $pageName . “
    ”;
    $HUIDIGEPAGINA = $_GET[“p”];
    if ($pageName === “Home”) { // index.html or index.php is usually the home page if this doesn’t work

             include("pagina/home.html");
         } else {
     
             include("pagina/" . $HUIDIGEPAGINA); //I removed the .html
       }
    

    }[/php]

    Though I don’t think that is going to work, I have a feeling we’re making it tougher than it should. 8)

    error 500

    PHP Parse error: syntax error, unexpected ‘/’ in /home/usernameplaceholder/public_html/index.php on line 81

    I think I got it

    [php] if (isset($_GET[“p”])) {
    echo $_GET[‘p’] . “
    ”;
    include(“pagina/” . $_GET[‘p’]); //I removed the .html

    } else {
    include(“pagina/home.html”);
    }[/php]

    there should be no blanks or anything…the contact page might still cause you problems.

    YOUR THE MAN!!! 8) ;D :wink:

    That did the trick! It works again…
    Thank you, thank you, thank you!
    The website works again… Yessssss :smiley:

    blows a kiss :-*

    You welcome and you can show me the love by giving me some Karma. :wink:

    Did it! :wink: :-*

    Sponsor our Newsletter | Privacy Policy | Terms of Service