Put link into variable? PHP

by 5 replies
6
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
#programming #link #php #put #variable
  • Php wont parse variables in this kind of bracket. Here is the right way:

    echo '<META HTTP-EQUIV="Refresh" Content="3; URL=' . $mylink . '">';
    • [ 1 ] Thanks
  • Not sure what you're doing wrong, if you could post your code that should help narrow down the problem.
    • [1] reply
    • 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.
      • [1] reply
  • 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

Next Topics on Trending Feed