0

I am creating weblinks on my site using PHP. Why do this and not do it manually - because I am accessing link information that is pulled from a mysql database. The query pulls out the data fine, the only trouble I am having is creating a text string with a link.

Two variables; $Loc_Name is the text I want to display, $Loc_Web is the URL.

Now i found the following which puts in the URL fine, but this does not display the text in the $Loc_Name output. How can I display the $Loc_Name value for the $Loc_Web url?

$Web_Link = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $Loc_Web);

Please Note ereg functions have been deprecated

3
  • Is the url embedded with other text of in a field by itself? Commented Feb 12, 2014 at 12:37
  • Hi Jeff, thanks for the reply, the url and text are both in individual fields. Volkan got the answer below.. Commented Feb 12, 2014 at 12:43
  • ereg functions have been DEPRECATED please use preg functions - php.net/manual/en/function.preg-replace.php Commented Feb 12, 2014 at 12:48

1 Answer 1

2

if $Loc_Web is just the url without html tags, why don't you use this?

echo "<a href='" . $Loc_Web . "'>" . $Loc_Name . "</a>"
Sign up to request clarification or add additional context in comments.

3 Comments

Such a simple thing... ...still learning PHP (in a backwards way!!), obviously missed a vital concept with the use of '" . and . "' to include a variable in a string.. ..not to far from vba, just different syntax...
it happens. if you find this answer useful you can accept it as an answer. thanks.
Done! Just waiting for the timer to go! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.