You are reading the article Guide To Types Of Php Annotations With Examples updated in December 2023 on the website Minhminhbmm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 Guide To Types Of Php Annotations With Examples
Introduction to PHP AnnotationsPHP annotations are basically metadata which can be included in the source code and also in between classes, functions, properties and methods. They are to be started with the prefix @ wherever they are declared and they indicate something specific. This information they provide is very useful to coders, helpful for documentation purposes and also an IDE may use this to display certain popup hint kind of things. The same annotation can also be used for other purposes besides validation such as to determine what kind of input needs to be given in a form and also for automation purposes. There are various kinds of annotations like the @var and @int types which can be used for specific uses as their name itself suggests.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax class Example { public $new; }Annotation is @var here and whenever it is encountered just before the piece of any code (public $new here for example) it indicates that the $new is to have a value of type integer as told by the annotation.
class Example { public $shop; }Annotations can also be used for specifying the range where it displays the maximum and the minimum values that are to be accepted as integer values for the function and the label gives the purpose of this function.
Types of PHP AnnotationsGiven below are the types:
1. Built-in AnnotationsThere are 2 built-in functions in annotations which are as follows:
a. Compiled: This annotation indicates that if the method/function should be JIT compiled or not. It is also a function scope type of annotation.
b. SuppressWarnings: This is another built-in annotation which means that any warnings thrown as part of the execution of the succeeding code below it must be suppressed.
2. Meta AnnotationsThese are those type of annotations which can be used to apply for other annotations. They are used for configuration of annotations.
a. @Annotations
There is a kind of annotation classes which will contain @annotation.
Code:
[@Annotation] class MyAnnoExample { }b. @Target
As the name suggests, this annotation indicates those types of class elements or a method upon which the annotation will be applicable.
Property annotation is just before the property class declaration.
Class which is allowed before the declaration of class.
Function is declared before the function declaration.
Method annotation allows proceeding the method declaration.
Annotation is allowed for proceeding to declaration of annotation class.
c. @Repeatable
This annotation means that it may be repeated any number of times when being used.
d. @Inherited
This can also be used on the other user defined annotation classes as a meta-annotation. These inherited annotations are automatically inherited to the respective sub-classes when they are used upon a superclass.
3. Custom AnnotationsThese are very similar to declarations of the normal class. Each element of the annotation type is defined by each of the property declarations.
Examples of PHP AnnotationsGiven below are the examples mentioned:
Example #1Code:
[@Annotation] [@Target("class")] class MyAnnoEx { [@Required] public string $prop; public array $arrayProp = []; public embedAnno $embed; } [@Annotation] [@Target(["class", "annotation"])] class embedAnno { } [@Annotation] [@Target("property")] class propAnno { } @Annotation @Target("method") class methodAnno { public string $val; public function __construct(string $val) { } }This is just a basic example showing the usage of all the different types of annotations which are shown above. All the ones in the example like embed annotation, property annotation, method annotation are custom annotations.
Example #2<?php /** * @Replace(“exmaple”, “for”, “annotation”) */ class MyNamedComponent { } echo str_replace(“First”, “Second”, “First Example”);
Output:
In this example we are naming the annotation as replace since the below code represents the usage of string replace function which is str_replace, an inbuilt function of PHP. Using this function, the first parameter passed in the function is replaced by the second one.
Example #3Code:
<!–Declaring First name for the form First_Name: <!–Declaring Last_Name for the form Last_Name: <!–Declaring Location for the form Stay location: <!–Declaring EMAILID for the form EmailID: <!–Declaring Password for the form Password: <!–Declaring Password for the form Gender: <input type=”radio” value=”Male” <input type=”radio” value=”Female” <?php if(example($_POST[‘confirm’])) { if(!example($error)) { } }
Output:
In this example, we are showing annotations in combination with the form validation in PHP. Using annotations we are labeling all the parameters which are required as input parameters to the form such as first and last name, email, location and password.
ConclusionWith the above examples we have noticed how annotations are a powerful tool to use and express metadata about our methods, classes or properties. We have also seen how to combine different kinds of annotations to declare workers who will perform certain tasks by writing some metadata about them. This makes them easy to find and gives actual information on whether or not they can be used.
Recommended Articles
This is a guide to PHP Annotations. Here we discuss the introduction to PHP annotations with types of annotations and respective examples. You may also have a look at the following articles to learn more –
You're reading Guide To Types Of Php Annotations With Examples
Complete Guide On Php Compiler With Zend Engine
Introduction to PHP Compilers
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
What is PHP Compiler?It is a special kind of program that turns the PHP statements into the machine level language so that it could be understood by the system’s processor. The processor of any system understands only binary code, which means the compiler converts the high level language into the binary form so that it could be understood and processed by the processor. Any program is meaningless without a compiler. All of the IDEs that provides a complete platform to edit and run the program is comprised of the compiler that compiles the program written in it to the machine level language. In actual terms, the compiler is nothing but just a program that assists in turning anything written using the statements into the binary form.
The role of compiler is not just to turn the code into the machine level language but also to make sure that the statement written in the program are error-free. When it comes to error checking, the compiler ensures that the program is conforming to the syntax and have used the predefined keywords appropriately. When the compiler finds the error, it lets the developer know about it by providing the brief details about the error and such errors are known as compile time error. In the error, it shows the line number in which the issue is occuring together with the kind of error. The error has to be rectified in order to let the compiler turns the code into the binary code that could be understood by the processor.
Zend Engine PHP compilerThe working of the Zend engine is very simple and has been defined below using the diagram. In normal terms, the PHP code is turned into the machine level language which is then processed by the processor. But when working with the Zend compiler, the PHP script is turned into the Zend Opcodes. The opcodes are then leveraged while the generation of the HTML page that is served to the client eventually. It works in a simple manner and provides additional features as compared to the normal compiler. The Zend Engine also offers the runtime engine that lets the user work with the program. Though the Zend engine provides the platform to compile, it has to load the PHP script into the memory before it could initiate the entire compiling process.
The compiler that we used in our local servers comes inbuilt in that. They just compile the code and let the processor handle the compiled file in order to render the application. All the programming languages have their own compiler that can understand the code written on that particular programming language. The time taken by the compilers to compile the program file depends on its size. If it’s a large file or the line of code are much more in that case the compiler will take more time comparatively and vice versa.
ConclusionThe PHP compiler is a program that set of statements written in PHP to compile. It is considered very essential to work with any of the programming language as without compiler the codes barely make sense to the system. It is helpful in terms of converting the codes to the binary data that the processor leverages to render the application or to bring the functionality to the application.
Recommended ArticlesThis is a guide to PHP Compiler. Here we discuss the introduction, what is PHP Compiler along with the working of Zend Engine in detail. You may also look at the following articles to learn more –
Defintion, Examples And Types Invested In Portfolio
What is Portfolio Investment
Portfolio investments are investments in a portfolio of assets, including stocks, bonds, securities, debentures, deposits, or other financial instruments/assets. These investments are primarily made with the expectation that they will yield good returns or capital appreciation (i.e.) an increase in the value of investments. Risk and returns are directly proportional (i.e.) the higher the risk, the higher the returns.
Start Your Free Investment Banking Course
Download Corporate Valuation, Investment Banking, Accounting, CFA Calculator & others
Explanation
Portfolio investments are assets acquired with the intention of maximizing wealth or earning income/ profits from the investment. This is a passive investment, as there won’t be any direct ownership or active management of assets. This can be either long-term or short-term; investors choose their investments based on their risk appetite and time period (i.e.) Long term or short-term.
Mutual funds and institutional investors predominantly deal with these investments. In the same way, pension funds and sovereign funds also invest in portfolios with a conservative approach. Risk tolerance is an important factor in choosing portfolio investments.
Features of Portfolio Investment
Portfolio investments are diversified, which reduces the risk by allocating the investments across various financial instruments, business sectors, and categories.
Investors’ risk tolerance and investment goals matter a lot in portfolio investments.
Stocks and bonds are predominantly considered portfolio investments but also include investment assets, a strategic investment method.
Example of Portfolio Investment
Mr. A wants to invest in a portfolio with moderate risks and returns. So, Mr. A plans to invest in the below portfolio. US Govt bonds offer a 2% yield of return per annum. This is a risk-free investment as the US Government provides it; at the same time, returns are also low. Blue-chip stocks offer around a 10% yield of return per annum. Dealing with equities always has risks, and the investments are not secured. So, the risk and returns both are high.
To have a moderate risk and returns, it is better to invest 50% in US Govt bonds and 50% in stocks, so the risk is also reduced, and the returns are averaged at 6%. In this case, returns are better than bonds but less than stocks, and at the same time, the risk is also reduced. If Mr. A wants more returns or low risk, it must decide by him, and he can change the proportion of the portfolio according to his risk tolerance and expectations of return.
Types of Portfolio Investment
There are different types of portfolios and different strategies for portfolio investment. It is up to the individual investor or the portfolio managers to choose the portfolio strategy based on the risk appetite and time horizon.
1. Hybrid Portfolio
A Hybrid portfolio is a diversified portfolio with a mix of high-risk and low-risk securities. It means investment in equities where risk and returns are high and in some fixed income securities like bonds, deposits, etc., where the risk and returns are comparatively lower than equities.
2. Aggressive Portfolio
An Aggressive portfolio invests in high-risk securities that will yield higher returns. The prime aim of this portfolio is to gain more returns from the investments, and their risk tolerance is at the higher end (i.e.) the investor in this portfolio is willing to take more risk in return for better gains.
They choose to invest in companies in the early stages of development with potential growth opportunities. They use the right business strategies where the risk is comparatively higher, and the returns also will be higher.
3. Defensive Portfolio
A Defensive portfolio is an investment in stocks dealing with essential/necessary goods. These stocks do well both in good times and bad times (i.e.) Even if the economy is bad, these stocks will perform as they deal with essential goods like food products, healthcare, household goods, etc., which are necessary for survival. This portfolio has less risk as they focus on essentials and yield better yields.
4. Income Portfolio
An Income portfolio is an investment in fixed income securities and dividend payout stocks that generate a regular source of income. The prime focus is to earn income from the investment. (E.g.) Bonds, deposits, Real estate investment trusts (REIT), etc., generate regular income through interest, rental income distribution, dividends, etc. These are low-risk investments and suitable for risk-averse investors.
5. Speculative Portfolio
What Amount Should be Invested in Portfolio?
The amount to be invested in the portfolio is at the discretion of the investors and the investment plan offered by the investment managers. There are monthly SIP plans and lump sum investments.
Portfolio Investment Management
Portfolio investment management is the process of selecting the stocks and securities for a portfolio and overseeing their performance, and managing the funds keeping in mind the investment goals, risk tolerance, and time period. It requires analytical and decision-making skills to choose the right stocks for investments. The portfolio manager strategically takes the buy and sell call of stocks and aims to generate maximum returns.
Advantages
The investor can choose the investment proportion considering the risk tolerance, return expectations, and time horizon.
Diversification of investments into different financial instruments helps to reduce risk and yield better returns.
Liquidity and flexibility exist in portfolio investment as the investor can exit from any particular investment at any time, and the remaining investment in the portfolio can be maintained.
Portfolio investments help to choose both fixed-income securities and capital appreciation investments. An Investor can choose the proportion of investment based on the strategic investment plan.
It is tough to track investment-related information constantly as the investments are diversified.
Proper securities and risk profile analysis needs to be carried out before making portfolio investments; otherwise, it may deliver desired returns.
It is tough for any individual investor to decide on a portfolio as it requires a lot of research and analysis; hence it creates a dependency for investors to rely on portfolio investment managers.
Financial knowledge is a must for investors to invest in portfolio investments.
Conclusion
Portfolio investments are good for those who want to balance their risk and returns and those who want to diversify their investments. The portfolio offers customization and helps investors to choose investments according to their risk tolerance, time horizon, and yield of returns. These services are offered by investment managers and other financial institutions that research and analyze securities and offer investment plans.
Recommended ArticlesWhat Is System Testing? (Definition, Types, Examples)
In software testing, what is system testing?
System testing entails testing the whole system. All of the modules/components are linked together to see whether the system performs as planned. After Integration Testing, System Testing is carried out. This is crucial for producing high-quality output.
Example of System TestingAn automobile is not built as a whole by a car manufacturer. Each component of the automobile, such as the seats, steering, mirror, brake, cable, engine, car structure, and wheels, is made independently.
After each item is manufactured, it is tested separately to see whether it functions as intended. This is known as unit testing.
Now, when each element is integrated with another part, the completed combination is tested to see whether the assembly has had any side effects on the functioning of each component and if both components are operating together as intended, which is referred to as integration testing.
When all of the pieces are put together and the automobile seems to be ready, it is not.
The entire car must be checked for various aspects as defined by the requirements, such as whether the car can be driven smoothly, if the breaks, gears, and other functionality are working properly, if the car does not show any signs of fatigue after being driven for 2500 miles continuously, if the color of the car is widely accepted and liked, and if the car can be driven on any type of road, including smooth and rough, sloppy and straight, and so on. This entire testing effort is known as System Testing, and
The example performed as anticipated, and the customer was satisfied with the amount of effort necessary for the system test.
System Testing – Approach
It is carried out after the Integration Testing has been finished.
It is mostly a sort of Black-box testing. With the use of a specification document, this testing assesses the system’s functionality from the perspective of the user. It does not need any internal system expertise, such as code design or structure.
It includes both functional and non-functional application/product domains.
What is the Purpose of System Testing?
Completing a full test cycle is critical, and ST is the stage when this is accomplished.
System Testing is carried out in a comparable setting to that of production, allowing stakeholders to obtain a solid picture of the user’s response.
It reduces the number of troubleshooting and support calls made following a deployment.
At this level of the STLC, both the Application Architecture and the Business Requirements are tested.
System testing is critical and plays a key part in providing a high-quality product to the consumer.
How Do You Run a System Test?It’s essentially a subset of software testing, and the Test Plan should always include room for it.
To test the system as a whole, requirements and expectations must be clear, and the tester must also understand how the program is used in real-timereal time.
In addition, the system’s functionality, performance, security, recoverability, and installability are all affected by the most commonly used third-party tools, OS versions, flavors, and architecture.
As a result, having a clear image of how the program will be utilized and what kinds of challenges it may encounter in real-time may be beneficial for testing the system. Furthermore, a requirements document is just as crucial as comprehending the program.
A clear and up-to-date requirements document may prevent a slew of misconceptions, assumptions, and queries for testers.
In summary, a clear and concise requirement document with the most recent revisions, as well as an awareness of real-time application use, may help ST be more productive. This testing is done in a methodical and organized way.
System Testing TypesST is known as a superset of all sorts of testing since it covers all of the primary types of testing. Although the emphasis on different forms of testing varies according to the product, the organization’s procedures, the timetable, and the needs.
Overall, it may be summarized as follows −
Functionality Testing − To ensure that the product’s functionality meets the established criteria while remaining within the system’s capabilities.
Recoverability Testing − This ensures that the system can recover from a variety of input mistakes and other failure scenarios.
Interoperability Testing − To determine whether or not the system is compatible with third-party goods.
Performance Testing − Verifying the system’s performance in terms of performance characteristics under different conditions.
Scalability Testing − To ensure that the system can scale in terms such as user scaling, geographic scaling, and resource scaling.
Reliability Testing − To ensure that the system can be used for a longer period of time without failing.
Regression Testing − To ensure the system’s stability as it integrates various subsystems and performs maintenance chores.
Testing of the system’s user guide and other help-related documents to ensure that they are valid and useful.
To ensure that the system does not enable unauthorized access to data and resources, security testing is performed.
Usability testing is performed to ensure that the system is simple to use, understand, and run.
More Types of System Testing
Graphical User Interface (GUI) Testing − GUI testing is used to see whether a system’s graphical user interface (GUI) performs as planned. The graphical user interface (GUI) is what a user sees when using a program. Buttons, icons, checkboxes, List boxes, Textboxes, menus, toolbars, dialog boxes, and other GUI elements are all tested.
Testing for Compatibility − Compatibility testing ensures that the generated product is compatible with a variety of browsers, hardware platforms, operating systems, and databases, as specified in the requirements specification.
Handling Exceptions − Handling Exceptions Testing is done to ensure that even if the product encounters an unexpected fault, it displays the relevant error message and does not cause the program to halt. The exception is handled in such a manner that the error is shown while the product recovers and the system is able to complete the wrong transaction.
Testing by Volume − Volume testing is a sort of non-functional testing in which a large volume of data is used to test. To test the system’s performance, for example, the database’s data volume is raised.
Stress Evaluation − Stress testing involves raising the number of users on an application (at the same time) until the program fails. This is done to see whether the application will fail at any point.
Sanity Checks − When a build is published with a change in the code or functionality, or if a problem has been repaired, sanity testing is conducted. It ensures that the modifications made did not impact the code and that no new issues have arisen as a result, and that the system continues to function normally. If a problem arises, the build will not be approved for further testing. In order to save time and money, rigorous testing is not performed on the build, which results in the build being rejected due to a problem discovered. Sanity testing is done for the specific modification or problem that has been resolved, not for the whole system.
Smoke Testing − Smoke Testing is a kind of testing that is done on a build to see whether it can be further tested or not. It ensures that the build is ready to test and that all-importanttime real features are operational. Smoke testing is carried out for the whole system, from start to finish.
Exploratory Testing − Exploratory testing is all about investigating the application, as the name implies. Exploratory testing does not include any scripted testing. Along with the testing, test cases are written. It emphasizes implementation over preparation. The tester is free to test independently, relying on his intuition, experience, and intelligence. In contrast to other strategies that employ the structural method to execute testing, a tester may select any feature to test first, i.e. he can choose the feature to test at random.
Adhoc Testing − Adhoc testing is unplanned testing that takes place without any documentation or preparation. The application is tested without any test cases by the tester. A tester’s goal is to break the application. To uncover the main faults in the program, the tester relies on his expertise, guesswork, and intuition.
Checking the installation − The purpose of installation testing is to ensure that the program is installed correctly. The installation of the program is the user’s first engagement with the product, hence it’s the most crucial phase of testing. The sort of installation testing required is determined by a number of elements, including the operating system, platform, software distribution, and so on.
ConclusionSystem testing is crucial because if done incorrectly, serious concerns might arise in the real world.
The properties of a system as a whole must be confirmed. Any webpage would be a basic example. If it isn’t well tested, the user may find the site to be very sluggish, or the site may crash if a big number of people log in at the same time.
These features cannot be checked until the whole website has been examined.
How To Write A Good Linkedin Summary? A Guide With Examples
blog / Career Why is a Good LinkedIn Summary Important and How to Write One
Share link
Struggling to write a good LinkedIn summary? This blog is a guide to help you with practical examples of well-written summaries and insights to help you stand out and make a lasting impression on potential employers and professional connections. These include highlighting your key skills and accomplishments and showcasing personal values and goals, among other things.
Why a Good LinkedIn Summary is ImportantFirst Impression: This is the first thing a visitor to your LinkedIn profile will notice. It gives them a brief overview of your background, activities, and potential contributions to the organizations.
Showcasing Strengths: Your summary helps highlight your strengths, abilities, and experiences to set you apart from the competition.
Search Engine Optimization: A well-written summary with pertinent keywords can boost your ranking in search results.
Networking: Using your summary to introduce yourself to potential contacts and connect with other experts in your field makes for a great networking strategy.
Differentiation: A well-written summary can highlight your particular value to a field or industry.
Hence, having a good LinkedIn summary creates a favorable first impression, helps showcase your brand, increases your visibility in search results, and helps you stand out from the competition.
How to Write a Good LinkedIn Summary Start with a Purposeful ApproachEstablish the goal of your summary: What do you want your audience to take away from this? Are you attempting to highlight your knowledge or expertise? Are you trying to connect with other businesspeople in your field? Be specific with your goals.
Activate Their InterestStart with an attention-grabbing headline or opening paragraph that compels the reader to continue reading.
Define Your Special Selling PointDescribe your Unique Selling Proposition (USP) or how you differ from competitors in your industry. Declare your area of expertise and highlight your strengths, abilities, and experience.
Write in the First PersonWrite a summary using the first-person narrative to establish a more intimate connection with your readers.
Use Concise LanguageAvoid industry jargon or buzzwords that might be confusing or off-putting to your readers; use clear, concise language instead.
Show, Don’t TellUse examples and stories to illustrate your achievements and demonstrate your skills and experience.
Use KeywordsIncorporate relevant keywords into your summary to optimize it for search engines; this makes your profile more visible to recruiters and potential employers.
Add MultimediaTo make your summary more exciting and visually appealing, consider including multimedia components like images, videos, or links to your portfolio.
Keep it CurrentUpdate your summary frequently to reflect any changes to your professional aspirations.
End with a CTAA clear Call to Action (CTA) after your summary will entice readers to contact you, visit your website, or proceed to the next professional development phase.
What Should You Put in the LinkedIn Summary SectionA succinct and interesting overview of who you are, what you do, and what you can offer should be included in your LinkedIn summary. These include:
Professional Headline:
Begin with a compelling headline that briefly describes your current position or area of specialization
Special Selling Point:
Describe your special qualities and why a potential employer should get to know you or hire you. Pay attention to your abilities, accomplishments, and experiences that set you apart from other professionals in your field
Education and Prior Experience:
Give a succinct overview of your professional background; mention your training, previous employment, certifications, or honors
Personal Brand:
Describe your work style, personality, and values in order to highlight your personal brand
Aspirations and Objectives:
Give the readers a sense of your direction and your desired outcomes by sharing your professional aspirations
Multimedia Content:
To make your summary more interesting and visually appealing, consider including multimedia components like images, videos, or links to your portfolio or personal website
ALSO READ: How to Present Your Job Change Reasons in Your Resume: Top Tips
LinkedIn Summary ExamplesSince we now have a rudimentary understanding of how to write a good LinkedIn summary, let’s look at some good and bad LinkedIn summary examples:
Example of a Poor LinkedIn SummaryA proven track record of high accomplishments in a variety of areas, as well as the ability to drive change. I am a highly organized person who believes in empowerment and teamwork. Also, I am highly adaptable, have a strong business sense, am a good communicator, am results-oriented, and am optimistic. I worked as a Software Engineer in India and am now looking for new opportunities.
Example of a Good LinkedIn Summary:I am a Software Engineer at XYZ company and have 5+ years of experience managing teams of 50–100 people, overseeing more than 30 projects with budgets ranging from $100,000 to $1.7 million. I worked as a Machine Learning Engineer at ABC company and on projects that used IBM Lotus Notes Domino, IBM WebSphere, and chúng tôi technologies. Please contact me if any new opportunities arise.
What Makes the Above Summary Effective?
The candidate has supported each skill with facts and figures to demonstrate their accomplishment.
In a few lines, the candidate has covered information about their current and previous work experience.
The summary includes their areas of expertise and skills, so that if a recruiter searches LinkedIn for candidates with these skills, their profiles will appear higher in the search results.
We’ve also provided two examples of sound LinkedIn summaries from professionals at different points in their careers:
LinkedIn Summary for BeginnersAs a recent computer science graduate with expertise in Java, Python, and C++, I am driven to create innovative software solutions that address real-world issues. I am a collaborative team player with excellent problem-solving skills who has experience developing mobile apps and web-based systems. My personal values of integrity, accountability, and transparency guide me in all of my work, and I am driven to deliver results on time and within budget. While continuing to learn and grow as a professional, I am looking for new opportunities to apply my skills and contribute to the technology industry.
LinkedIn Summary for Experienced ProfessionalsA good LinkedIn summary is a great way to introduce yourself and your skills to potential employers or clients. By including relevant information and proofreading it, a well-written summary can help you stand out from other applicants. Do explore Emeritus’ course page to learn more about various learning opportunities to fast-track your career.
Write to us at [email protected]
Php Ajax Tutorial With Example
What is Ajax?
AJAX full form is Asynchronous JavaScript & XML. It is a technology that reduces the interactions between the server and client. It does this by updating only part of a web page rather than the whole chúng tôi asynchronous interactions are initiated by chúng tôi purpose of AJAX is to exchange small amounts of data with server without page refresh.
JavaScript is a client side scripting language. It is executed on the client side by the web browsers that support JavaScript.JavaScript code only works in browsers that have JavaScript enabled.
XML is the acronym for Extensible Markup Language. It is used to encode messages in both human and machine readable formats. It’s like HTML but allows you to create your custom tags. For more details on XML, see the article on XML
Why use AJAX?
It allows developing rich interactive web applications just like desktop applications.
Validation can be performed done as the user fills in a form without submitting it. This can be achieved using auto completion. The words that the user types in are submitted to the server for processing. The server responds with keywords that match what the user entered.
It can be used to populate a dropdown box depending on the value of another dropdown box
Data can be retrieved from the server and only a certain part of a page updated without loading the whole page. This is very useful for web page parts that load things like
Tweets
Commens
Users visiting the site etc.
How to Create an PHP Ajax applicationWe will create a simple application that allows users to search for popular PHP MVC frameworks.
Our application will have a text box that users will type in the names of the framework.
We will then use mvc AJAX to search for a match then display the framework’s complete name just below the search form.
Step 1) Creating the index pagechúng tôi
HERE,
“onkeyup=”showName(this.value)”” executes the JavaScript function showName everytime a key is typed in the textbox.
This feature is called auto complete
Step 2) Creating the frameworks pagechúng tôi
<?php $frameworks = array("CodeIgniter","Zend Framework","Cake PHP","Kohana") ; $name = $_GET["name"]; $match = ""; for ($i = 0; $i < count($frameworks); $i++) { if (strtolower($name) == strtolower(substr($frameworks[$i], 0, strlen($name)))) { if ($match == "") { $match = $frameworks[$i]; } else { $match = $match . " , " . $frameworks[$i]; } } } } echo ($match == "") ? 'no match found' : $match; Step 3) Creating the JS scriptauto_complete.js
function showName(str){ if (str.length == 0){ document.getElementById("txtName").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari } else {// code for IE6, IE5 } } } }HERE,
“if (str.length == 0)” check the length of the string. If it is 0, then the rest of the script is not executed.
“if (window.XMLHttpRequest)…” Internet Explorer versions 5 and 6 use ActiveXObject for AJAX implementation. Other versions and browsers such as Chrome, FireFox use XMLHttpRequest. This code will ensure that our application works in both IE 5 & 6 and other high versions of IE and browsers.
Step 4) Testing our PHP Ajax application
Type the letter C in the text box You will get the following results.
The above example demonstrates the concept of AJAX and how it can help us create rich interaction applications.
Summary
AJAX is the acronym for Asynchronous JavaScript and XML
AJAX is a technology used to create rich interaction applications that reduce the interactions between the client and the server by updating only parts of the web page.
Internet Explorer version 5 and 6 use ActiveXObject to implement AJAX operations.
Internet explorer version 7 and above and browsers Chrome, Firefox, Opera, and Safari use XMLHttpRequest.
Update the detailed information about Guide To Types Of Php Annotations With Examples on the Minhminhbmm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!