TinyPortal

General => Chit chat => Topic started by: akulion on September 24, 2006, 11:54:50 AM

Title: Using " and ' in PHP [help]
Post by: akulion on September 24, 2006, 11:54:50 AM
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>";

Title: Re: Using " and ' in PHP [help]
Post by: eldacar on September 24, 2006, 11:57:37 AM
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.
Title: Re: Using " and ' in PHP [help]
Post by: akulion on September 24, 2006, 11:59:50 AM
ah I see

ok then ill try the same code above using single quoted echo statements and see how it goes :D Thanks
Title: Re: Using " and ' in PHP [help]
Post by: akulion on September 24, 2006, 12:03:34 PM
oh wow!

its easier too using single quotes

got it working in 3 mins!

:D thanks again
Title: Re: Using " and ' in PHP [help]
Post by: eldacar on September 24, 2006, 12:17:20 PM
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';
Title: Re: Using " and ' in PHP [help]
Post by: akulion on September 24, 2006, 12:21:17 PM
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 :)
Title: Re: Using " and ' in PHP [help]
Post by: stormlrd on September 24, 2006, 12:45:14 PM
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
Title: Re: Using " and ' in PHP [help]
Post by: akulion on September 24, 2006, 01:32:23 PM
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
Title: Re: Using " and ' in PHP [help]
Post by: stormlrd on September 24, 2006, 01:55:04 PM
;) Ive listed several tool links in my board check them out sometime lol.
Title: Re: Using " and ' in PHP [help]
Post by: akulion on September 24, 2006, 01:59:43 PM
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
Title: Re: Using " and ' in PHP [help]
Post by: stormlrd on September 24, 2006, 02:03:45 PM
my games are in alpha and beta m8 but they will get there lol thanks
Title: Re: Using " and ' in PHP [help]
Post by: bloc on September 24, 2006, 03:24:53 PM
I always found single ones easiest - because then you don't need to escape any double inside html tags. ;)
Title: Re: Using " and ' in PHP [help]
Post by: stormlrd on September 24, 2006, 04:01:48 PM
yep lol i learned that one the hard way.