Advanced Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Putting variables inside variables?

  1. #1
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 130 Times in 117 Posts

    Default Putting variables inside variables?

    Is this possible? I'm working with Wordpress for my site, and wanted to do some customization of my theme. The theme displays a tiny bit of info about the author of each post like the username they login with, how many posts they've written, and if they give a "bio" about themselves it includes that too...

    What I want to do is to add a small bit of funny text below where it tells how many posts the user has made via PHP. I've found a script I'm using right now which I have gotten to work just fine. The problem is, some of the phrases I want to use would require to display the user's name (their login name), but I can't seem to figure out how to put that variable inside the array of things to say.

    Here's the code, then below that I'll post the variation I tried to call the users' names.
    The first code is what wordpress uses internally to call the post author's username/nickname
    The second code is the random phrase script
    PHP Code:
                       <?php echo $curauth->nickname?>
    PHP Code:
    <?php 
                              $slyterm
    [] = '...We think';
                              
    $slyterm[] = 'Yes, we\'re counting.';
                              
    $slyterm[] = 'Support your <del>local</del> <strong><del>global</del></strong> <strong>GALACTIC</strong> writer people!';
                              
    $slyterm[] = 'We are assuming this one was written with "love" as well... (no guarantees)';
                              
    $slyterm[] = 'The buzz on the street is that this post was written with <em>love</em>...';

                              
    srand ((double) microtime() * 1000000);
                              
    $random_number rand(0,count($slyterm)-1);
                              echo (
    $slyterm[$random_number]);
                              
    ?>
    Now here is what I added to try and call the user's nickname into the array...

    PHP Code:
    $slyterm[] = 'We believe that $curauth->nickname only writes these to get the attention they were lacking as a child...'
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  2. The Following 2 Users Say Thank You to TheJoshMan For This Useful Post:

    jimbob79 (10-14-2008),Maynard (10-12-2008)

  3. #2
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    PHP Code:
    $slyterm[] = "We believe that $curauth->nickname only writes these to get the attention they were lacking as a child..."
    Jeremy | jfein.net

  4. The Following User Says Thank You to Nile For This Useful Post:

    TheJoshMan (10-12-2008)

  5. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    $slyterm[] = sprintf('We believe that %s only writes these to get the attention they were lacking as a child...', $curauth->nickname);
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. The Following User Says Thank You to Twey For This Useful Post:

    TheJoshMan (10-12-2008)

  7. #4
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 130 Times in 117 Posts

    Default

    Quote Originally Posted by Nile View Post
    PHP Code:
    $slyterm[] = "We believe that $curauth->nickname only writes these to get the attention they were lacking as a child..."

    that outputs like this...

    We believe that only writes these to get the attention they were lacking as a child...
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  8. #5
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 130 Times in 117 Posts

    Default

    Quote Originally Posted by Twey View Post
    Code:
    $slyterm[] = sprintf('We believe that %s only writes these to get the attention they were lacking as a child...', $curauth->nickname);

    This one also outputs the same as above, it just completely removes that section that should display the post author's nickname.

    We believe that only writes these to get the attention they were lacking as a child...
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  9. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That means that $curauth->nickname is empty.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. The Following User Says Thank You to Twey For This Useful Post:

    TheJoshMan (10-14-2008)

  11. #7
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    Run this code:
    PHP Code:
    if(empty($curauth->nickname) || !isset($nickname)){
    die(
    'It is empty, or got unset.');
    }
    echo 
    "It's fine, its not unset, or empty"
    Tell us the output.
    Jeremy | jfein.net

  12. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    $slyterm[] = "We believe that" . $curauth->nickname . "only writes these to get the attention they were lacking as a child...";
    echo $slyterm[];

  13. #9
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default

    Quote Originally Posted by Nyne Lyvez View Post
    PHP Code:
                       <?php echo $curauth->nickname?>
    PHP Code:
    <?php 
                              $slyterm
    [] = '...We think';
                              
    $slyterm[] = 'Yes, we\'re counting.';
                              
    $slyterm[] = 'Support your <del>local</del> <strong><del>global</del></strong> <strong>GALACTIC</strong> writer people!';
                              
    $slyterm[] = 'We are assuming this one was written with "love" as well... (no guarantees)';
                              
    $slyterm[] = 'The buzz on the street is that this post was written with <em>love</em>...';

                              
    srand ((double) microtime() * 1000000);
                              
    $random_number rand(0,count($slyterm)-1);
                              echo (
    $slyterm[$random_number]);
                              
    ?>
    Now here is what I added to try and call the user's nickname into the array...

    PHP Code:
    $slyterm[] = 'We believe that $curauth->nickname only writes these to get the attention they were lacking as a child...'
    Can I have your permission to use this script? I might like to use it for random quotes or something.

  14. #10
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 130 Times in 117 Posts

    Default

    umm... sure you can use it.... If you can use it. LOL

    It's not my script man, so go right ahead. I can't even remember where I found it. I didn't see any disclaimer that came with it, so I'm assuming it's free for distribution.
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

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
  •