Multilined String in PHP
Multilined string in PHP can be written in many different ways to have your codes look clean and neat.
Method 1: You can break the lines into multiple strings on multiple lines using a period in front of the assignment sign in order to concatenate them.
Usage:
$st = “This is the book”;
$st .= ” that I really like to read in my spare time.”;
$st .= ” I bring it with me while I’m traveling this summer.”;
Method 2: Use excerpt sign and close it at the end of all the lines. You must write exact same name as you previously defined it.
Usage:
$st = <<<STOPHERE
<p>This is the book
that I really like to read in my spare time. I bring it with me while I’m traveling this summer.</p>
STOPHERE;
Find the location of a file
__FILE__ is a built-in php global variable that you can use to get the location of a file that’s executing.
Usage: echo __FILE__;
Result (Linux): /var/www/html/my-domain.com/TestDir/setExpiredDate.php
(Windows): C:\Documents and Settings\myname\My Documents\www\TestDir\setExpiredDate.php
Using backslash when echo quotation marks
Sometimes you’ll see quotation marks in a string that represent exact language that has come from somebody else. The quotation mark is also used to designate speech acts in fiction and poetry. For example: Mr. Douglas, who was working in his field that morning, said, “The alien spaceship appeared right before my own eyes.”
In this case, if you want to echo this string out on a php page, you will have to add a backslash in front of each quotation mark to ensure that it will appear on the html page.
echo "<P>Mr. Douglas, who was working in his field that morning, said, \”The alien spaceship appeared right before my own eyes.\”</P>";
Apache Variables
After installing Apache and PHP server, you can check the Apache variables by using a php page to echo them on the browser. If you need to modify the Apache config to adapt your server environment and to meet your needs, you can always change the .conf file and restart your Apache server.
Use the Apache variables below to check your server:
| DOCUMENT_ROOT | Document root |
| HTTP_ACCEPT | Accept header of an HTTP request |
| HTTP_ACCEPT_ENCODING | Accepted encoding (deflate or gzip) |
| HTTP_ACCEPT_LANGUAGE | Accept-Language from HTTP header |
| HTTP_CONNECTION | Connection header of the HTTP request |
| HTTP_HOST | Internet host |
| HTTP_USER_AGENT | Client initiating web request |
| PATH | Directories the server looks |
| REMOTE_ADDR | Address of the client |
| REMOTE_PORT | Port of client |
| SCRIPT_FILENAME | Absolute path of script |
| SERVER_ADDR | Server’s address |
| SERVER_ADMIN | Admin of server |
| SERVER_NAME | Server name set |
| SERVER_PORT | Port the web server is running on |
| SERVER_SIGNATURE | Version of the server software |
| SERVER_SOFTWARE | Server’s identification string, found in HTTP header |
| GATEWAY_INTERFACE | Version of the CGI spec used |
| SERVER_PROTOCOL | Protocol server is currently using |
| REQUEST_METHOD | Request method, such as GET, PUT, POST, etc. |
| QUERY_STRING | Query string if one exists |
| REQUEST_URI | Uniform Resource Identifier |
| SCRIPT_NAME | Path and name for the current script |
| PATH_TRANSLATED | Absolute path on the web server’s file system |
| PHP_SELF | Location of PHP script relative to document root |
Apache + PHP installation error: The specified module could not be found.\r\n in Unknown on line 0
Common Apache error: “PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\\php5\\ext\\php_pdo_mysql” in the Apache log file (C:\Program Files\Apache Group\Apache2\logs\error.log).
I just installed Apache and Tomcat servers on my new laptop in order to run php and java at the same time; however I ran into an issue with MySQL database connection when I execute a php page. There’re a few things that you can try to make your server work properly.
First: check php.ini file to make sure that you have extension_dir = “C:\php5\ext”.
Second: go to php directory, copy the libmysql.dll file and paste it to Apache bin directory. Remember not to remove it from php directory. Then restart your server to take effect.