How to put hyperlink value in variable?

Posted on 2008-06-17
Last Modified: 2010-04-21

I have one hyperlink title is "MyLink" which points to ""

I want to store hyperlink value( in variable $target
so that i can simply print the text (not link) >

Also if you can help

i have ["   ]
I want to remove at the very end [ " ]
so that result will be without "
how to do this.
Question by:theredcode
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
LVL 14

Expert Comment

by:Vel Eous
ID: 21805930

$target = "";


<a href="<?PHP echo $target; ?>" title="my link">My Link</a>

<?PHP echo str_replace ( '"', '', '"' ); ?>
LVL 49

Expert Comment

ID: 21805947
Where do you have it in? in a variable?

$string = '[" ]';

$url = preg_replace('/(^\s*\[\s*)|("\s*\]\s*$)/', '', $string);

Author Comment

ID: 21806133
" , i have removed so no wrries..

The thing is i have one variable when i print it using echo it prints as link but i just want text...

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.


Author Comment

ID: 21806155
i ahve hyperlink in variable,
just want target address not a clickable link...plz help i am stuck with it...
LVL 49

Accepted Solution

Roonaan earned 250 total points
ID: 21806189
Like this?

$variable = '<a href="link">click me</a>';

$link = preg_match('#href=")[^"]*)"#i', $variable, $m) ? $m[1] : false;


Expert Comment

ID: 21806221
odd, are you using some sort of CMS?

if your varible is set using
$myLink =  "";
then when you use
echo ($myLink);
it should output just as text.

otherwise the only way you SHOULD get a link display is if you used
<a href="<?php echo $myLink; ?>">My Link</a>
or some variation of that

there is no obvious reason that it would intuitively print display the text as a link unless you are using some sort of CMS or development software that has that conversion built in

Author Comment

ID: 21806969
Plz visit

Under [Parent Directory] You will see some hyperlinks
( example.mp3   index2.php   readme_wimpy_button....   wimpy.html   wimpy.php   wimpy_button.swf)

These hyperlinks are dynamically created by a loop. My problem is, my loop outputs them as a link rather than a target address (no link).

In above case, the hyperlink "example.mp3 " points to >>
This is what i need to be printed, just the target text i.e.

I hope this wil given some idea, sorry for my way of putting this like this.

Expert Comment

ID: 21814339
is it possible to see the loop that creates the output?

Author Closing Comment

ID: 31468081
I got idea fromt this comment so plz adjust. I really thank every xpert for his time and efforts...

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question