Fall Sale! Code FALL2024 takes 25% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security
eBook: Digging Into WordPress
Digging Into WordPress: Take your WordPress skills to the next level.
Related Posts

PHP Notes Plus

Here are some basic PHP expressions and statements for ez reference..

Common Statements

"\n" = new line
"\t" = tab
"\r" = carriage return
"\$" = dollar sign
"\"" = double quote

Example usage:

"\n\t<category>$category->cat_name</category>"
echo '<!-- Category LiveBookmarks Plugin by Monzilla Media ( monzillamedia.com ) -->' . "\n";
echo "\n\t<!-- Pink Floyd " . " Meddle -->\n\n";

echo Multiple Lines of Code

echo <<<END
   ... line of code ...
   ... line of code ...
   ... line of code ...
END;

Example usage:

<?php 
   function hide_post_preview() {
      echo <<<END
         <style type="text/css">
            #preview {
               display: none;
            }
         </style>
      END;
   }
   add_action('admin_head', 'hide_post_preview');
?>

Determine System Path

After preparing a .php file with the following line of code, upload it to the target directory and open with your favorite browser:

<?php echo dirname(__FILE__); ?>

Access PHP System Information

After preparing a .php file with the following line of code, upload it to the target directory and open with your favorite browser:

<?php phpinfo() ?>

Determine Absolute Path

An absolute path, or full path, refers to the static location of a resource as it exists relative to the root directory within a computer’s file system. A directory’s absolute path is universal and is independent of any relative working directory, dynamic variables, or combined paths. An absolute path includes the root directory and "descending series of subdirectories leading to the end file".

Here is a mighty handy PHP script that provides a simple method of determing the absolute path of a directory. Simply save this script as a file called "absolutepath.php" and upload it to the location for which you wish to determine the absolute (server) path.

The absolute path will appear when you point your browser to the location of the file, absolutepath.php. To determine the absolute path of a different directory, simply move the absolutepath.php file to that directory and go to that location with your browser.

<?php echo $_SERVER['DOCUMENT_ROOT']; ?>

About the Author
Jeff Starr = Web Developer. Security Specialist. WordPress Buff.
GA Pro: Add Google Analytics to WordPress like a pro.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
USP Pro: Unlimited front-end forms for user-submitted posts and more.
Thoughts
I disabled AI in Google search results. It was making me lazy.
Went out walking today and soaked up some sunshine. It felt good.
I have an original box/packaging for 2010 iMac if anyone wants it free let me know.
Always ask AI to cite its sources. Also: “The Web” is not a valid answer.
All free plugins updated and ready for WP 6.6 dropping next week. Pro plugin updates in the works also complete :)
99% of video thumbnail/previews are pure cringe. Goofy faces = Clickbait.
RIP ICQ
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.