Welcome to WebmasterWorld Guest from 184.73.3.107

Forum Moderators: coopster & jatar k

using "" for img src in an Array

Am I in for trouble down the road?

   
6:58 pm on Aug 23, 2002 (gmt 0)

10+ Year Member



Hi gang:

Very simple thing: I'm using an array to have a random imager on some new pages.

When I embed the img src in the array, I can't use the traditional "" around the .jpg, otherwise it messes up the array.

EXAMPLE:
This works:
array("<img src=../images/someimage.jpg width=150 height=130 border=1 alt=Image Title>",

This doesn't:
array("<img src="../images/someimage.jpg" width="150" height="130" border="1" alt="Image Title">",

Of course, the first example spits out the image code with no "" in it. I tested it in IE 5.0 and NN 4.7 - and it works. I know from our site stats that there's NO browsers below either of those examples.

But I'm wondering if a lack of "" around the img src tags will cause trouble in other browsers?

Any thoughts on this? Or how to work around it?
Thanks for your time

7:10 pm on Aug 23, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I assume we're talking PHP here. Have you tried escaping the "" like this:

src=\"../images/someimage.jpg\"

alternately you may be able do it automatically by this:

$string = "<img src="../images/someimage.jpg" width="150" height="130" border="1" alt="Image Title">";
array(addslashes($string));

I didn't test either of these.

[edited by: lorax at 7:12 pm (utc) on Aug. 23, 2002]

7:10 pm on Aug 23, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



did you try escaping the quotes

like

array("<img src=\"../images/someimage.jpg\" width=\"150\" height=\"130\" border=\"1\" alt=\"Image Title\">"

11:07 pm on Aug 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Plain and simple:

array('<img src="../images/someimage.jpg" width="150" height="130" border="1" alt="Image Title">';

You can almost always avoid having to escape quotes by using a quoting operator that is not used in the string itself. If you were using perl that wouldnīt be any problem since it has a real quoting operator. But even in php it is quite easy using the heredoc syntax as explained in [php.net...]

<?php
$str = <<<EOD
<p class="ac">Example of string
spanning multiple lines
using 'heredoc' syntax.</p>
EOD;
?>

Note the use of both " and ' without having to escape those characters since we use heredoc syntax to mark beginning and end of the string.

3:29 am on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



andreasfriedrich

Thanks for the tip. Umm..but don't you still need to close your parens? ;)

10:58 am on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You sure do. Thatīs were copying & pasting from the previous posts gets you...
11:59 pm on Aug 26, 2002 (gmt 0)

10+ Year Member



got a question on this one ... does the Array in php would hold the actual picture file on this? Would this make it load faster? just curious. :)
12:39 am on Aug 27, 2002 (gmt 0)

10+ Year Member



I'm pretty sure it's just the text strings.
12:40 am on Aug 27, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Yes, you just store the image path in the array.
4:54 am on Aug 27, 2002 (gmt 0)

10+ Year Member



is it possible to store a picture file in an array? just thinking ...
4:57 am on Aug 27, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I don't really think you would want to.

If you are have a good thought post a new thread and see what comes up.

5:41 pm on Aug 27, 2002 (gmt 0)

10+ Year Member



Andreas!

Your very simple solution of using single quotes - ' ' instead of "" works like a charm.

Knowing about the heredoc syntax will also be helpful for the future, I'm sure.

A thousand thank-you's... I'm sorry I didn't test the other examples, but I appreciate everyone's input.

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month