将php调用作为href值返回
I'm quite new to using php so im not sure if this is possible or not;
What I'm looking to do is call a php function from within a href tag, and use the returned value as the tag..
for example, i have the following code:
HTML
<a href= 'tele.php'> <img src="images/image1" alt="Preview1" /> </a>
then:
PHP
<?php
return header("Location: tel:762347723447");
exit;
?>
I want the href tag to be what the php code returns: "Location: tel:762347723447". Is it possible to do this? or am I going about this the wrong way?
header()
returns void, so that PHP code doesn't return anything.
But you probably want something like this:
<?php
function foo() {
return "tel:762347723447"
}
?>
<a href= '<?php echo foo(); ?>'> <img src="images/image1" alt="Preview1" /> </a>
You're going about this the wrong way. I'm unsure of what you're trying to do, but if you want your HTML to call tele.php, get the output of some PHP and replace the HREF, look into AJAX
HTML
<a id="this-link-id" href="tele.php"><img src="images/image1.jpg" alt="Previe1" /></a>
<script>
$.post( $('#this-link-id').attr('href'), {}, function( response ) {
$('#this-link-id').attr('href', response);
});
</script>
PHP (tele.php)
<?php
echo 'tel:762347723447';
die();
I suggest you to use jQuery and ajax to it then you can have effect which you want.
more info: http://api.jquery.com/jQuery.ajax/