Referencing a picture based on a url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GJM
Forum Newbie
Posts: 10
Joined: Fri May 01, 2009 3:25 am

Referencing a picture based on a url

Post by GJM »

I have some php code that is printing a sites 'logo' and 'name' at the top of an email and making it a link back to the site.

It looks like this:

Code: Select all

<td>
            <h1 style="font-family:Arial,Helvetica,sans-serif; font-size:18px;"><a href="<?php print $site_url; ?>" title="<?php print $site_title; ?>"><?php print $logo; ?> <?php print $site_name; ?></a></h1>           
          </td>
Now, I'd like to use a scaled down version of the logo so it is not so big in the email.
Lets call the image: small-logo.png
and it resides in my http://www.mysite.com/image directory

I tried to replace the

Code: Select all

<?php print $logo; ?>
With something like this:

Code: Select all

<?php $small_logo="www.mysite.com/image/small-logo.png" print $small_logo; ?>
I thought that as long as I "defined" the variable first that I could get it to be displayed by using 'print' or 'echo' in the code.

It is probably very obvious that I am new at this, but I'd appreciate any help you can give.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Referencing a picture based on a url

Post by cpetercarter »

Try

Code: Select all

<?php $small_logo="www.mysite.com/image/small-logo.png"; print $small_logo; ?>
There are two separate statements/commands in this code - the first defines $small_logo, the second prints $small_logo. There needs to be a ";" at the end of each.
Alkis
Forum Commoner
Posts: 31
Joined: Fri Mar 26, 2010 8:41 am

Re: Referencing a picture based on a url

Post by Alkis »

Along with the above correction from cpetercarter:
1) Never ommit the protocol if you are going to request something using the domain in a URL:
2) The image path must be on a valid html image tag in order to be displayed:

So this line:
<?php $small_logo="www.mysite.com/image/small-logo.png" print $small_logo; ?>

Correct it with this:
<?php $small_logo='<img src="http://www.mysite.com/image/small-logo.png" />'; print $small_logo; ?>
GJM
Forum Newbie
Posts: 10
Joined: Fri May 01, 2009 3:25 am

Re: Referencing a picture based on a url

Post by GJM »

THANK YOU Alkis!!!!

Code: Select all

<?php $small_logo='<img src="http://www.mysite.com/image/small-logo.png" />'; print $small_logo; ?>
worked like a charm.

learning php I find is kinda like patting my head and rubbing my belly at the same time :lol: (I'm not that coordinated) but when you see it done, it looks easy :lol:

Again Thanks
Alkis
Forum Commoner
Posts: 31
Joined: Fri Mar 26, 2010 8:41 am

Re: Referencing a picture based on a url

Post by Alkis »

Glad you solved it :)

Learning a bit HTML and maybe JavaScript along with php I think is a must.

Happy coding :wink:
Post Reply