Put link into variable? PHP

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

    echo '<META HTTP-EQUIV="Refresh" Content="3; URL=' . $mylink . '">';
    {{ DiscussionBoard.errors[5214604].message }}
  • Profile picture of the author hhunt
    Not sure what you're doing wrong, if you could post your code that should help narrow down the problem.
    {{ DiscussionBoard.errors[5214911].message }}
    • Profile picture of the author bocceman
      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.
      Signature

      Play bocce? Check out our cool selection of Bocce Ball Sets or the only drink koozie that keeps score!

      {{ DiscussionBoard.errors[5218087].message }}
      • Profile picture of the author Terry Crim
        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."\">";
        {{ DiscussionBoard.errors[5220088].message }}
  • Profile picture of the author SeeSharp
    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
    {{ DiscussionBoard.errors[5221918].message }}

Trending Topics