一个好的php代码,无论放到windows还是linux,不同版本的php上,都能正确的输出结果,才是一个好代码。
说起来容易的事,做起来并不是很轻松,很多时候写代码都是功能导向,当前环境,要赶时间立马见效果,基本就是怎么方便怎么来了。
但是为了写出一个好的代码和后期减少调试时间,写每一个代码都要斟酌考虑是否能够适应你所能想到的困难,每次解决一个,日积月累下来,你的代码就会伸缩自如了。
相对路径是对于当前代码文件所在文件夹来说。
绝对路径是相对于根文件夹来说。
当代码需要依赖别的文件时,就需要统一代码的包含路径。
代码执行时出现找不到文件,多数是由于没有定义好路径。
我推荐大家写绝对路径来写程序,相对路径一旦移动后就容易出现找不到要包含的文件。
用到的php函数和常量
dirname
__FILE__
DIRECTORY_SEPARATOR
推荐写一个初始化文件 initialize.php
// Define the core paths // Define them as absolute paths to make sure that require_once works as expected // DIRECTORY_SEPARATOR is a PHP pre-defined constant // (\ for Windows, / for Unix) defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR); defined('SITE_ROOT') ? null : define('SITE_ROOT', dirname(__FILE__)); defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes'); // load config file first require_once(LIB_PATH.DS.'config.php'); // load basic functions next so that everything after can use them require_once(LIB_PATH.DS.'functions.php'); // load core objects require_once(LIB_PATH.DS.'session.php'); require_once(LIB_PATH.DS.'database.php'); // load database-related classes require_once(LIB_PATH.DS.'user.php'); |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools