How to make a text link PHP

Learn how to make text a link in PHP with an example. See how to use the PHP built-in functions to create clickable links.

Creating a Text Link with PHP

Creating a text link with PHP is quite easy. It is simply a matter of using the built-in function echo and the tag <a> to create a link. The syntax is as follows:

echo "<a href='URL'>Link Text</a>";

Where URL is the link destination and Link Text is the clickable text. As an example, let's create a link to the home page of W3Schools:

echo "<a href='https://www.w3schools.com/'>Visit W3Schools!</a>";

This code will create the following link: Visit W3Schools!

It is also possible to add additional attributes inside the <a> tag. For example, we can add a title attribute to the link like so:

echo "<a href='https://www.w3schools.com/' title='Visit W3Schools'>Visit W3Schools!</a>";

The title attribute will be displayed when the user hovers over the link with the mouse. In this case, the title attribute is set to the same text as the link text, but it can be anything you like.

Creating a text link with PHP is quite a simple task. All you need to do is use the echo function and the <a> tag, and you can create a simple link in no time!

Answers (0)