John Lee
John Lee

Reputation: 55

PHP text as hyperlink in echo

I am pretty sure this will be an easy task to do for some PHP programmers I just can't figure it out how to do it. I am displaying some info from my database but want to be able to display it as Hyperlink text instead of the whole website so when someone click on "Website" it will take them to the url. Here is my code:

 <li style="margin-left: 50px;font-family: Myriad Pro Bold ! important;"><b style="margin-right: 20px;">Website:</b> <?php echo $row->website; ?></li></li>

I am looking forward to add 2 texts to the code for example:

 <li style="margin-left: 50px;font-family: Myriad Pro Bold ! important;"><b style="margin-right: 20px;">Website:</b> <?php [SHOW: (**Website** as a hyperlink text) (**Blog** as a Hyper link text) echo $row->website; ?></li></li>

Thank you!!!

Upvotes: 0

Views: 1120

Answers (2)

Dadou
Dadou

Reputation: 1008

If the href is already within a string, you have two options:

Single/Double quotes

$string = '<a href="http://google.com">Google</a>';

Escaping

$string = "<a href=\"http://google.com\">Google</a>";

Otherwise, you can insert PHP into your link, like so:

<a href="<?php echo $row->link; ?>">Google</a>

If this is not what you are looking for, I am sorry I misunderstood the question.

Edit:

I suggest you use CSS rather than inline styles, would simplify your code and look less sloppy.

Upvotes: 0

PaulProgrammer
PaulProgrammer

Reputation: 17630

<a href="<?php echo $row->website; ?>"><?php echo $row->blog; ?></a>

Just guessing that $row has a member called blog as well that has the title, and that $row->website is the full url (http://bleh)

Upvotes: 3

Related Questions