homepage Welcome to WebmasterWorld Guest from 54.227.171.163
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
using "" for img src in an Array
Am I in for trouble down the road?
Ranger

10+ Year Member



 
Msg#: 548 posted 6:58 pm on Aug 23, 2002 (gmt 0)

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


 

lorax

WebmasterWorld Administrator lorax us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 548 posted 7:10 pm on Aug 23, 2002 (gmt 0)

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]

jatar_k

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



 
Msg#: 548 posted 7:10 pm on Aug 23, 2002 (gmt 0)

did you try escaping the quotes

like

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

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 548 posted 11:07 pm on Aug 23, 2002 (gmt 0)

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.

lorax

WebmasterWorld Administrator lorax us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 548 posted 3:29 am on Aug 24, 2002 (gmt 0)

andreasfriedrich

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

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 548 posted 10:58 am on Aug 24, 2002 (gmt 0)

You sure do. Thatīs were copying & pasting from the previous posts gets you...

copongcopong

10+ Year Member



 
Msg#: 548 posted 11:59 pm on Aug 26, 2002 (gmt 0)

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. :)

olwen

10+ Year Member



 
Msg#: 548 posted 12:39 am on Aug 27, 2002 (gmt 0)

I'm pretty sure it's just the text strings.

jatar_k

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



 
Msg#: 548 posted 12:40 am on Aug 27, 2002 (gmt 0)

Yes, you just store the image path in the array.

copongcopong

10+ Year Member



 
Msg#: 548 posted 4:54 am on Aug 27, 2002 (gmt 0)

is it possible to store a picture file in an array? just thinking ...

jatar_k

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



 
Msg#: 548 posted 4:57 am on Aug 27, 2002 (gmt 0)

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.

Ranger

10+ Year Member



 
Msg#: 548 posted 5:41 pm on Aug 27, 2002 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved