Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Put link into variable? PHP (https://www.warriorforum.com/programming/502131-put-link-into-variable-php.html)

Amsterdam 11th December 2011 04:42 AM

Put link into variable? PHP
 
Hi,

I'm trying to add a paused re-direct to a page using:

Code:

echo '<META HTTP-EQUIV="Refresh" Content="3; URL=$mylink">';
But whenever I give the variable '$mylink' a value such as 'www.warriorforum.com' it won't read the value and tries to re-direct to $mylink instead.

What am I doing wrong?

T

Nikolas 11th December 2011 05:07 AM

Re: Put link into variable? PHP
 
Php wont parse variables in this kind of bracket. Here is the right way:

echo '<META HTTP-EQUIV="Refresh" Content="3; URL=' . $mylink . '">';

hhunt 11th December 2011 07:00 AM

Re: Put link into variable? PHP
 
Not sure what you're doing wrong, if you could post your code that should help narrow down the problem.

bocceman 11th December 2011 08:32 PM

Re: Put link into variable? PHP
 
Nik. is correct. Echos wrapped in single quotes will not interpret. Do what he said or wrap the echo in double quotes so it interprets variables. I am on my DROID or I would post a snippet.

Terry Crim 12th December 2011 06:13 AM

Re: Put link into variable? PHP
 
If the variable is set do this:


echo "<META HTTP-EQUIV=\"Refresh\" Content=\"3; URL=$mylink\">";

OR

echo "<META HTTP-EQUIV=\"Refresh" Content=\"3; URL=".$mylink."\">";

SeeSharp 12th December 2011 12:22 PM

Re: Put link into variable? PHP
 
Hello Amsterdam,

Your problem is that you used ' instead of " after echo. With ' php will not parse variables in the string while in " it will.
So your correct syntax would be
echo "<META HTTP-EQUIV= \"Refresh\" Content=\"3; URL=$mylink\">";

Of course you need to escape " in the code then.

Hope that helped you.

Greetings


All times are GMT -6. The time now is 05:07 AM.