TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   stupid simple question (http://www.talkphp.com/absolute-beginners/2279-stupid-simple-question.html)

bmathers 02-18-2008 11:18 PM

stupid simple question
 
how can i output an image in this code;

PHP Code:

$config["M_Paintball_100"]="
<h1>Times:</h1> 9.45am – 2pm or 11.30am – 3.30pm on a half day, full day 9.45am – 3.30pm.
"


everything ive tried doesnt seem to work. This code is a snippet from a message pop up box that is called when clicked on.

Wildhoney 02-18-2008 11:54 PM

Which image? Where you getting the image from?

Andrew 02-19-2008 01:28 AM

Code:

<img src="path/to/image.gif" alt="Alt text" />
Like that?

bmathers 02-19-2008 08:12 AM

thats what i thought but its not working, ive tried this but cant get it too work

PHP Code:

$config["M_Paintball_100"]="
<h1>Times:</h1> 9.45am – 2pm or 11.30am – 3.30pm on a half day, full day 9.45am – 3.30pm.</br><br>
<img src="
../images/stag.gif"/>"


bmathers 02-19-2008 08:12 AM

Quote:

Originally Posted by Wildhoney (Post 11014)
Which image? Where you getting the image from?

just an imagein my images folder, the code above is one of many in a file called message.oho, which is called when the user clicks to find more information

Wildhoney 02-19-2008 09:18 AM

php Code:
$config["M_Paintball_100"] = '<h1>Times:</h1> 9.45am – 2pm or 11.30am – 3.30pm on a half day, full day 9.45am – 3.30pm.<br /><br />
<img src="../images/stag.gif"/>'
;

bmathers 02-19-2008 09:27 AM

can you explain what the difference is between the single and double qoutes, sorry for being simple, justtrying to understand everything.

ReSpawN 02-19-2008 10:55 AM

Quote:

Originally Posted by bmathers (Post 11033)
can you explain what the difference is between the single and double qoutes, sorry for being simple, justtrying to understand everything.

Double quotes can be used like this;
PHP Code:

echo "Hello, my name is $name."

This most likely, when defined $name, exports Hello, my name is insert_name_here

The same doesn't go for the single quotes although they are a lot easier to use. Since you'll make echo's like this;
PHP Code:

echo '<a href="link.htm">link</a>';
// and of course
$query mysql_query('SELECT * FROM table WHERE name = "'.$name.'"'); 

Adam would be more qualified to explain it into more depth but those are the basics really. Also, double quotes understand the usages of "\n" (HTML Enter) and "\r" (HTML Tab).

Good luck!

SOCK 02-19-2008 02:27 PM

... that's correct ReSpawN, but I think the real issue was non-escaped double quotes. That's the reason Wildhoney corrected the string.

In any event, bmathers, you should spend some time reading through the PHP Manual, especially the language reference.

flyingbuddha 02-19-2008 03:35 PM

Just to expand on Sock's explanation a tiny bmathers, using quotes inside quotes (as with your example), you're causing confusion to the interpreter, it doesn't know when the sentence is ending and when it's beginning.

That means it's taking '../images/stag.gif' and trying to parse/ call it rather than outputting it, as you're intending.

Couple of bits re. ReSpawn's points,

1. If you use a variable in a string, enclose it in curly braces:
PHP Code:

// not strictly necessary but easier to spot
echo "Hello, my name is {$name}."

2. There's a slight performance benefit from using apostrophe's over quotes when dealing with strings. Apostrophe's are taken as literals so it doesn't try to parse data as strings in quotes' do.

Wildhoney 02-19-2008 07:34 PM

I also published a little article on double and single quotes over here.

ReSpawN 02-19-2008 07:49 PM

You should built in a feature when the post is one above the poster, auto add a thanks. :-P


All times are GMT. The time now is 05:48 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0