0

My hosts recently updated their PHP to 5.3 (without warning) and I now have to replace the code for my page navigation on my index page. This is what I'm currently using:

<? if (eregi(".shtml", $load)) {if (!@readfile("$load")) { readfile("error.shtml"); }  } if (!eregi(".shtml", $load)) {if (!@readfile(include("/home/content/j/p/l/jplegacy/html/coranto/news.txt") )) ;}?>

This is what I use as a sample in my links to navigate with:

<a href="?load=archive/archive.shtml">Archive</a>
<a href="?load=about.shtml">About Us</a>

I looked at two different techniques, preg_match() and stristr().

preg_match() outputs my error page and news.txt file from Coranto, but doesn't navigate me to the pages like in the links above. What can I do here to make that work?

stristr() doesn't give me the warnings, but it doesn't navigate the page and only outputs my Coranto news page. If this would be better, what can I do to make this work?

What do I need to do to fix this? I am completely lost. :(

hakre
  • 193,403
  • 52
  • 435
  • 836

1 Answers1

0

ereg(i) is considered to be deprecated. You should use preg_match for regular expressions as the preg is faster than the other engine. Also, if you want ends with ".shtml" that regex is wrong, and you don't need to resort to regular expressions. Ends with .shtml is "^*.shtml$". If you do choose to use preg_match, all preg_match regular expresions, like perl, are surrounded by "/" (slash), so the correct regex would look like:

 preg_match("/^.*\.shtml$/", $load)

But on to the better solution for "ends with .shtml". Generally you shouldn't use regular expressions unless the situation actually calls for them (they're significantly slower than using substr and matching the last part of the string), simple matches like that don't qualify.

 if (substr($test, sizeof($load) - 7, 6 )) == '.shtml') { ... }
hsanders
  • 1,913
  • 12
  • 22
  • Alright, now I'm getting this: Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/content/j/p/l/jplegacy/html/index.php – Terry Alan Davis Jr Aug 23 '12 at 17:26
  • @TerryAlanDavisJr You're much better off using the substr implementation, regular expressions are much less efficient and should only be used when something can't be matched in one step with substr. – hsanders Aug 23 '12 at 20:16
  • @TerryAlanDavisJr Updated version should work. – hsanders Aug 23 '12 at 20:18
  • Question on that. It seems to not load the pages still using substr, I'm not sure what's going on. Do I need to change it ?test=?load= in my navigation menu? – Terry Alan Davis Jr Sep 03 '12 at 23:31
  • @TerryAlanDavisJr It would need to be ?load=pagename.shtml Any additional GET parameters would be passed by doing ?load=pagename.shtml&foo=bar&baz=bo&etc=etc – hsanders Sep 04 '12 at 17:26