search
HomeBackend DevelopmentPHP TutorialCommon functions and keywords in the basic part of PHP

  1. bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]] ]] )
  2. explain:This requires that you place calls to this function prior to any output, including and tags as well as any whitespace.
  3. example:setcookie("TestCookie", $value, time ()+3600);
  4. bool define ( string $name , mixed $value [, bool $case_insensitive = false ] ) //Define a constant
  5. const CONSTANT = 'Hello World'; //Use the practical keyword const to define a constant Constant, the effect is the same
  6. example:define("CONSTANT", "Hello world.");
  7. bool defined ( string $name ) //Check whether a constant exists
  8. bool isset ( mixed $var [, mixed $ ... ] ) //Check if a variable exists
  9. void unset ( mixed $var [, mixed $... ] ) // Release a variable
  10. bool function_exists ( string $function_name ) // Check if a function Exists
  11. string get_class ([ object $obj ] ) //Get the class name of an object
  12. array get_object_vars ( object $obj ) // Return an associative array composed of object attributes
  13. bool file_exists ( string $filename ) // Check if the file or directory exists
  14. Comparison operator
  15. $a == $b equals, if $a equals $b after type conversion.
  16. $a === $b is congruent if $a is equal to $b and their types are also the same.
  17. $a != $b is not equal, if $a is not equal to $b after type conversion.
  18. $a $b is not equal, if $a is not equal to $b after type conversion.
  19. $a !== $b is not congruent if $a is not equal to $b, or their types are different.
  20. $a $a > $b is greater than, if $a is strictly greater than $b.
  21. $a $a >= $b is greater than or equal to $a if $a is greater than or equal to $b.
  22. PHP supports an error control operator: @. When placed before a PHP expression, any error message that expression may produce is ignored.
  23. Execution operator, backtick operator is invalid when safe mode is activated or shell_exec() is turned off.
  24. $output = `ls -al`;
  25. echo "
    $output
    ";
  26. ?>
  27. There are two string operators . The first is the concatenation operator ("."), which returns the concatenated string of its left and right arguments. The second is the concatenation assignment operator (".="), which appends the right argument to the left argument.
  28. Array operator
  29. $a + $b Union Union of $a and $b.
  30. $a == $b is equal TRUE if $a and $b have the same key/value pair.
  31. $a === $b is congruent TRUE if $a and $b have the same key/value pairs and are of the same order and type.
  32. $a != $b is not equal TRUE if $a is not equal to $b.
  33. $a $b is not equal TRUE if $a is not equal to $b.
  34. $a !== $b is not equal. TRUE if $a is not equal to $b.
  35. The type operator instanceof is used to determine whether a PHP variable belongs to an instance of a certain class:
  36. class MyClass{}
  37. class NotMyClass{}
  38. $a = new MyClass;
  39. var_dump($a instanceof MyClass);
  40. var_dump($a instanceof NotMyClass);
  41. ?>
  42. The above routine will output:
  43. bool(true)
  44. bool(false)
  45. bool is_a ( object $object , string $class_name [, bool $ allow_string = FALSE ] ) //Return TRUE if the object belongs to this class or this class is the parent class of this object
  46. foreach loop array or object
  47. foreach (array_expression as $value)
  48. statement
  49. foreach (array_expression as $key => $value)
  50. statement
  51. require and include are almost exactly the same, except for the way failure is handled. require generates an E_COMPILE_ERROR level error when an error occurs. In other words, it will cause the script to abort and include will only generate a warning (E_WARNING), and the script will continue to run.
  52. include 'vars.php';
  53. The require_once statement is exactly the same as the require statement. The only difference is that PHP will check whether the file has already been included, and if so, it will not include it again.
  54. goto: (compared to C language, it is a castrated product)
  55. The goto operator can be used to jump to another location in the program.The target position can be marked with the target name followed by a colon, and the jump instruction is the goto followed by the mark of the target position.
  56. goto in PHP has certain limitations. The target location can only be in the same file and scope, which means that it cannot jump out of a function or class method, nor can it jump into another function. It also cannot jump into any loop or switch structure.
  57. You can break out of a loop or switch. The usual usage is to use goto instead of multiple levels of break.
  58. goto a;
  59. echo 'Foo';
  60. a:
  61. echo 'Bar';
  62. ?>
  63. The above routine will output:
  64. Bar
Copy code

php


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software