SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've asked this before under a different topic, so it may have gotten lost.


    I'm using variables inside links, and since spaces aren't allowed, the variables get mashed up.

    For example:

    <a href="index.php?$FOOname">

    $FOO is the variable, and "name" is just part of the string.

    PHP thinks the variable is "$FOOname" (not that I blame PHP!). Is there a way to "force" the variable names so that PHP understands whats a variable and what's not?

    Thanks!

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here are a few ways :
    Code:
    <?php $FOO = 'hi'; ?>
    
      <a href="index.php?<?php echo $FOO; ?>name">link</a>
    
      <?php echo '<a href="index.php?'.$FOO.'name">'; ?>link</a>
    
      <?php echo "<a href='index.php?{$FOO}name'>link</a>"; ?>
    
      <?php echo "<a href=\"index.php?{$FOO}name\">link</a>"; ?>
    They all create : <a href="index.php?hiname">link</a> except the third puts single quotes in the link.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Sausalito, Ca
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The way that I have done this in the past is this:

    <a href="http://www.someurl.com/?name=<? echo $someValue ?>"

    I think this is what your asking? I believe that in order to get the value from a php varaible into html, you have to echo it as above.

    If that's not what your asking, the other thing is that you can use %20 to encode a space.

  4. #4
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a quick note,
    using
    <?=$foo?>
    is the same as
    <?echo $foo?>
    except it looks a lot nicer

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Things to know about <?=$foo?> :

    1. Only works in PHP4+
    2. Won't work if open_short_tags is set to off in php.ini
    3. XML Parser doesn't work with short tags
    4. Not part of PEAR standard

    Something to consider at least, does save typing though.

  6. #6
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Philip! The {} was exactly what I was looking for since I want to do it without the messy concatenation (which I forgot to mention).


    Thanks to everyone else for the other suggestions too, I learned a few new tricks today.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •