I need to echo $qs within an echo, but what I have isn't working....

Discussion in 'PHP' started by qwikad.com, Mar 17, 2013.

  1. #1
    Hi guys!

    I need to show a $qs within an echo, but I have no clue how. Right now I have this and it's not showing:

    echo '<a href="/?<?php echo $qs; ?>do=reportabuse&confirm=1">confirm</a>';

    How do I make <?php echo $qs; ?> to actually show in this instance?


    Thanks!
     
    Solved! View solution.
    qwikad.com, Mar 17, 2013 IP
  2. #2
    
    echo '<a href="/?' . $qs . 'do=reportabuse&confirm=1">confirm</a>';
    
    PHP:
     
    nico_swd, Mar 17, 2013 IP
    qwikad.com likes this.
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    As nico_swd's code shows, you are already IN PHP if you are using echo, so you don't need to open and close PHP again, you need to close the current string, add your variable, and open the string up again for the rest.

    Though I would suggest using commas (delimiters) instead of periods (string additions) -- it's a hair faster, uses less memory, but more importantly it executes in the order you THINK it's going to... Mind you, comma's only work when echoing and there are cases where string addition is preferred... but think about this example:

    <?php
    function echotest() { echo 'is '; }
    
    echo 'This ',echotest(),'a test<br />';
    echo 'This '.echotest().'a test<br />';
    ?>
    Code (markup):
    It will output:
    This is a test
    is This a test
    Code (markup):
    Why does that code do that? The string addition runs the function BEFORE the resulting string is sent to echo, while using comma's each 'piece' is sent one after the other. It's a distinction a lot of people starting out with PHP (and even many people who've done it for years) can get confused by.

    As such, I'd have it worded thus:
    echo '<a href="/?',$qs,'do=reportabuse&confirm=1">confirm</a>';
    Code (markup):
    But really, either way will work since $qs is a variable.

    Generally speaking the whole <?php ?> two or three times a line crap most people vomit up just seems like sloppy coding to me (another strike against poorly coded crap like turdpress)... as a rule of thumb I prefer in most all the code I write to only <?php once at the start of my PHP file, and ?> once at the end, and that's IT. REALLY if I had my way, <?php ?> would be removed from the PHP specification as unnecessary and running contrary to the methodology of sane/secure code.
     
    deathshadow, Mar 17, 2013 IP
    nico_swd and qwikad.com like this.
  4. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,373
    Likes Received:
    1,720
    Best Answers:
    31
    Trophy Points:
    475
    #4
    Thanks, guys! It's working.
     
    qwikad.com, Mar 17, 2013 IP
  5. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #5
    great, now you can mass report people to harrrass their accounts and services in bulk by adding them to a text list and pressing one submit button.
     
    ezprint2008, Mar 17, 2013 IP
  6. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,373
    Likes Received:
    1,720
    Best Answers:
    31
    Trophy Points:
    475
    #6
    LOL. On the contrary, this will stop spider/bot based flagging of our users' ads.
     
    qwikad.com, Mar 17, 2013 IP
  7. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #7

    Nice, if you get it working you should send it to craigslist. They need a new system instead of all their troll'ers they have that stalk the site and try to slander,undermine and delete/ban posts for their bottom-level entertainment. :D
     
    ezprint2008, Mar 20, 2013 IP