TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 19, 2024, 10:36:59 PM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,195
  • Total Topics: 21,220
  • Online today: 128
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 42
  • Total: 42

Using " and ' in PHP [help]

Started by akulion, September 24, 2006, 11:54:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

akulion

hi

Ok to my understnding when you use " (double quotes) to echo out a statement in PHP, you can call functions / variable etc without having to close the echo statement as in the case of the ' (single quotes) yea?

What I want to know is that in the code below for recent topics (mod version) the arrays send values - would these need to be in '' or should they be taken out?

Currently I get an error when trying to run this code:



global $scripturl;
$what=ssi_recentTopics('10', array('13','58'), 'array');

echo "<table border='0' width='100%' cellspacing='1' cellpadding='4' class='bordercolor'>";
echo "<tr class='catbg3'><td valign='middle'>Subject</td><td valign='middle'>Board</td><td valign='middle'>Poster</td><td valign='middle'>Time</td></tr>";

foreach ($what as $topic)
  {
    echo "<tr><td class='windowbg' valign='middle'>$topic['link']";
    // Is this topic new? (assuming they are logged in!)
    if (!$topic['new'] && $context['user']['is_logged'])
      echo "<a href='$scripturl?topic=$topic['topic'].from$topic['time']#new><img src='$settings['images_url']/$context['user']['language']/new.gif alt='$txt[302]' border='0' /></a>";
      echo "</td><td class='windowbg2' valign='middle' >$topic['board']['link']</td>";
      echo "</td><td class='windowbg2' valign='middle' >$topic['poster']['link']</td><td class='windowbg2' valign='middle' >";
      if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
      echo "<a href='$topic['href']'><img src='$settings['images_url']/icons/last_post.gif alt='$txt[111]' title='$txt[111]' border='0' style='float: right;' /></a>";
      echo "<span class='smalltext'>$topic['time']</span></td></tr>";
  }

echo "</table>";


eldacar

You can use either, but always remember to escape the 'opposite' quote, or simply escape them all. SMF usually uses single quotes because it's slightly faster I think.

akulion

ah I see

ok then ill try the same code above using single quoted echo statements and see how it goes :D Thanks

akulion

oh wow!

its easier too using single quotes

got it working in 3 mins!

:D thanks again

eldacar

If you use single quotes you can put the variables straight into the text though, you have to do something like

echo 'text yay', $context['data'], 'more text yay';

akulion

yea thats the problem i was having with double quotes - or maybe i was doing it wrong because this was giving errors:


echo" text yay $context['data'] more text yay";


but doing the single quoted echo worked just fine - so switched over to it :)

stormlrd

yall want the tutorial? lmao double quotes allow the use of vars inside the echo string but accent does not you have to come out of accent put var in than go back into accent.

I'll find you that tut ;)

http://us3.php.net/manual/en/function.echo.php

and lesson 2 operators in php lol

http://us3.php.net/manual/en/language.operators.php

akulion

aahhh so I would have had to use:

echo" text yay {$context['data']} more text yay";


with the {}

cool! Thanks for the site- i didnt even know it existed :D

stormlrd

;) Ive listed several tool links in my board check them out sometime lol.

akulion

Questors gate here i comeeeee!

WOW!!!! Man that red dragon theme is WAY COOL!!!!

WOW! but there seems to be some error - i assume ur testing it