- Single index.php PHP script to load different page using URL Variable
- #1: Strategy behind Coding:
- #2: The main code to produce different page from the same script:
- Welcome to the home page
- Welcome to the about page
- Welcome to Contact page
- Find and Extract All links From a HTML String in PHP
- Example 1: Get All Links From HTML String Value
- Example 2: Get All Links From a Web Page
- Related Posts:
- css - Style multi page links (index.php?first_page) - PHP
- Answer
- Solution:
- Share solution ↓
- Additional Information:
- Didn't find the answer?
- Similar questions
- Write quick answer
- About the technologies asked in this question
- PHP
- CSS
- HTML
- Welcome to programmierfrage.com
- Get answers to specific questions
- Help Others Solve Their Issues
- Latest questions:
- 778 php - Posts List not displaying in WordPress admin panel
- 151 php - How do I can resolve the error regarding "installable set of packages in Laravel 5.5 ( laravelcollective/html couldn't be install. )
- 665 php - Laravel and passport: POST method returns MethodNotAllowedHttpException
- 519 php - Socialite stateless auth
- 323 php - Save multiple inputs incremented
- 86 javascript - Client not receiving emails from page
- 116 Nested if statement in PHP MySQL SELECT
- 670 php - The queries on symfony4 / twig
- 121 php - Add a custom chosen date to cart item on add to cart action in Woocommerce
- 307 php - Change a specific product button text in a Woocommerce product category page
- Users questions:
- mysql
- Warning: Undefined array key "program" in E:\xampp\htdocs\pi\alumni.php on line 27 Warning: Undefined array key "enter_course" in E:\xampp\htdocs\pi\alumni.php on line 31 Warning: Undefined array key "enter_address" in E:\xampp\htdocs\pi\alumni.php on line 32
- Rename existing images with keyword in WordPress PHP
- codeigniter
- Class "web_profiler.controller.profiler" does not exist after upgrading symfony 3.4 to 4.4 version
Single index.php PHP script to load different page using URL Variable
Y ou should have many links like http://www.domain.com/index.php?page=home OR http://www.domain.com/index.php?page=about where different pages are shown from a single script. [In this case index.php is the script]. Now the question is how to make such kind of system…
Basically, what we can do is, use PHP GET method to pass variable URL to the server and response different pages accordingly. Have a look at the online demo… If, you think you can get the concept from the source code, then here is the link:
Read on below to know how we can implement this…
#1: Strategy behind Coding:
- We shall fetch the page variable from the URL using PHP GET method.
- We shall make a function in which we will pass the page variable using argument.
- Inside the function there will be a switch case to determine what page the client has requested for. We shall use different echo for different page requests…
#2: The main code to produce different page from the same script:
Keeping the above strategy in mind, here is the code… Note that we have assumed the script name to be diff-page.php. Change the links to match your file. Also check the Download Package to know how exactly it works:
'; case '': //When it is null case 'home': echo 'Welcome to the home page
'; echo 'This is the home page.
'; break; case 'about': echo 'Welcome to the about page
'; echo 'This is the about page
'; break; case 'contact': echo 'Welcome to Contact page
'; echo 'This is contact page
'; > > ?>Home Page | About Page | Contact Page
That was pretty simple, right? Note that when we pass the URL as diff-page.php?page=contact PHP GETs the $_GET[‘page’] variable as contact. Then it passes that through the layout function which calls switch to echo relevant pages.
So, the only thing you have to take care is, providing exact file name of the script file [diff-page.php] and the page variables [home, contact, about].
Well that’s it. Although there are many other methods of doing this, but personally I use this as my preferable method. Do give us your feedback and suggestions. Also if you think you know a better algorithm, do share it with us!
Find and Extract All links From a HTML String in PHP
Inside this article we will see the concept of find and extract all links from a HTML string in php. Concept of this article will provide very classified information to understand the things.
This PHP tutorial is based on how to extract all links and their anchor text from a HTML string. In this guide, we will see how to fetch the HTML content of a web page by URL and then extract the links from it. To do this, we will be use PHP’s DOMDocument class.
DOMDocument of PHP also termed as PHP DOM Parser. We will see step by step concept to find and extract all links from a html using DOM parser.
Example 1: Get All Links From HTML String Value
Inside this example we will consider a HTML string value. From that html value we will extract all links.
Create file index.php inside your application.
Open index.php and write this complete code into it.
Google Youtube Online Web Tutor