How to echo <a href> to link to a php function???????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hustler
Forum Newbie
Posts: 6
Joined: Thu Jul 21, 2005 2:26 am

How to echo <a href> to link to a php function???????

Post by hustler »

I have 3 questions and would be thankful in any answers I can get. Lets start with the most important one, which is in the subject.

1. How do I echo a <a href> tag to link to another php function?
For Example:
<?php
echo "<a href=\"<?php a_function() ?>\">LINK</a>";
?>

I keep getting an error. I also tried without the <?php ?> tags but it takes me to the wrong link. I then also tried putting \"<\?php a_function() \?>\" as the target but that also took me to a nonexisting page.

2. Is there any way to detect OnClick javascript with PHP?

3. How do I transfer variable data from javascript to PHP?
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

what you need is to break the string in the middle to insert function call

Code: Select all

echo "<a href='".a_function()."'>LINK</a>";
that's it!
nyy2000
Forum Newbie
Posts: 15
Joined: Tue Jul 12, 2005 12:40 am

Post by nyy2000 »

2. What exactly are you willing to do? I guess you can redirect to PHP script with get method when onClick event occured.

Not directly tranfering variable to PHP, but I would do save info on cookie, and when PHP page is loaded, I will make PHP code to read the cookie.
hustler
Forum Newbie
Posts: 6
Joined: Thu Jul 21, 2005 2:26 am

Post by hustler »

Thanks guys you have really helped a lot. For the <b>harrisonad</b> solution, it ran the function after echoing it. I was trying to put the function in a link so when you click on it, it would run it then not while it was in the echo.

To use JavaScript and PHP I had the PHP call the javascript function, which then created cookies. Then I use PHP to access those cookies.

Thanks again; you guys rock!!!!
Post Reply