4 Replies - 273 Views - Last Post: 01 April 2019 - 09:55 AM Rate Topic: -----

#1 f1uke   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-April 19

PHP with HTML... with PHP (?)

Posted 01 April 2019 - 02:00 AM

Hi everyone,

I am not that good at PHP, but I usually solves my issues myself, but this time I need some expert assistance. I am sure it's not a big problem for you guys, but I simply can't wrap my brain around it.

I am trying to make a PHP variable, with some HTML and this works fine, but then I need the HTML to contain another PHP variable, and then it fails.

It looks something like this:

$weblink = '<img src="http://domain.net/portal/uploads/<?php echo $filename;?>" width = "200" height = "200">';


The $weblink variable is then sent via PHP mail, and the outcome should be, that the image from the link, is being displayed in the email. But it's not working. In the source of the email, it shows the link to the image as this: http://domain.net/po...l/uploads/<?php echo $filename;?> and not like this: http://domain.net/po...s/image123.jpg. If I replace the link in the code, with the direct link to the image, then it is displayed in the mail. I have tested that the $filename variable contains the name and filetype of the image file.

Can someone help me here?

Is This A Good Question/Topic? 0
  • +

Replies To: PHP with HTML... with PHP (?)

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4226
  • View blog
  • Posts: 13,399
  • Joined: 08-June 10

Re: PHP with HTML... with PHP (?)

Posted 01 April 2019 - 02:11 AM

View Postf1uke, on 01 April 2019 - 11:00 AM, said:

I am trying to make a PHP variable, with some HTML and this works fine, but then I need the HTML to contain another PHP variable, and then it fails.

Neither PHP nor variables are parsed inside single quoted strings. Cf. http://php.net/strings

there are two major solution: split the string or use a template:
$weblink = '<img src="http://example.com/portal/uploads/' . $filename . '" width = "200" height = "200">';


// I often prefer this due to its better readability
$img = '<img src="http://example.com/portal/uploads/%s" width = "200" height = "200">';
$weblink = sprintf($link, $filename);


This post has been edited by Dormilich: 01 April 2019 - 02:12 AM

Was This Post Helpful? 1
  • +
  • -

#3 f1uke   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-April 19

Re: PHP with HTML... with PHP (?)

Posted 01 April 2019 - 03:09 AM

Thank you, Thank you, Thank you!
It works!!!
Spent several hours on this already, so I am extremely happy!
Thank you very much :)
Was This Post Helpful? 0
  • +
  • -

#4 benanamen   User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 235
  • Joined: 28-March 15

Re: PHP with HTML... with PHP (?)

Posted 01 April 2019 - 09:38 AM

The simplest way and cleanest IMO is to just switch the quotes around.

$weblink = "<img src='http://example.com/portal/uploads/$filename' width = '200' height = '200'>";  

Was This Post Helpful? 1
  • +
  • -

#5 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4226
  • View blog
  • Posts: 13,399
  • Joined: 08-June 10

Re: PHP with HTML... with PHP (?)

Posted 01 April 2019 - 09:55 AM

View Postbenanamen, on 01 April 2019 - 06:38 PM, said:

The simplest way and cleanest IMO is to just switch the quotes around.


Although you can easily overlook the fact, that there is a variable inside the string (not to mention how easy you find them*)


* - which--of course--also depends on the quality of your code highlighting
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1