try to attach <?php tags, plese help.

coacalli

New Member
Messages
10
Reaction score
0
Points
0
Greetings, this is my problem.

I'm far from a versed coder on php but try to do my best with wht i have.

this is what i have.

i've a mailer on php that sends a bunch of variables to the user depending on the request.

the mail that u get has a html, css styled page that contains the info the user requested and, u know, promotional ads, institucional head banner and stuff... a predefined format.

the thing is i tend to change my mind a lot about looks and it seems to me to be quite a dragg to make my format and then put a lot of backslashes every coutation mark on the code so i'm able to import the format on the body of the mail. (am i getting my self clear? english is... just... so... tree twisted witches watches each switch of tree swiss swatch watches)

on the end i finish with something like:

$varHeaders = "something";
$varBody_content = "something else";
$varSubject = "other something";
$varTo = "thepoorbastardi'msendingthemail";

$varBody_format = "lots of html code with the \ every single time a \" is on the text"
."and somewhere on the text such \"variables\" as <span class=\"content\" >$varBody_content</span>"
." or maybe <div id=\"to\">$varTo</div> "
."You get the idea"
;


So, my question after all this is: How can i get a html file that has php vars stated as $something as the value of another variable with out have the need of translate it into php?

on other words, is there a way to:

$varNeed_htmlpage = something('myhtml.html');

or something that can do the \ for me.


thanks a lot.
 

sarvar

New Member
Messages
82
Reaction score
0
Points
0
If you don't want to put backslashes often, just use single quotes around the html. For example like this.

PHP:
$variable = '<div id="test">This is a html without the need of backslashes</div>';
 

akkudreamz

New Member
Messages
183
Reaction score
0
Points
0
use the PHP adslashes() function
Ref:W3schools

About the other part if you wana put the static content part into another file you can do it and include it into your PHP script just like mentioned above by VPmase

hope this helps


If you need to remove those slashes somewhere in your code you can use the stripslashes function
 
Last edited:

freecrm

New Member
Messages
629
Reaction score
0
Points
0
This is something I am working on now.

If you are explaining what I think you are explaining, here is an example php code and variables blended with html that should help. (This was part of a form - obviously)

PHP:
<?php 
$fromname = stripslashes($_POST['fromname']);
$fromemail = stripslashes($_POST['fromemail']);
$toemail = stripslashes($_POST['toemail']);
	
$headers  = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= "Content-Transfer-Encoding: 7bit\n"; 
$headers .= 'From: Sender <'.$fromemail.'>' . "\n";
$headers .= 'Reply-To: '.$fromemail."\n";
$headers .= 'X-Mailers: PHP /'.phpversion() . "\n";
$subject = $_POST['subject'];
$message = $_POST['msg'];

	
	
	if (@mail($toemail,stripslashes($subject),stripslashes($message),stripslashes($headers)))
	{
		echo ('<p>Your message has been sent.</p>');
	}
	else
	{
		echo ('<p>Your message has failed to send.</p>');
	}

As you can see, the whole section is in php so you have to use 's to contain/ break out of the relevant code. The same principal can be used in subject and message.

i.e.
PHP:
<?php
$message = 'this is a test page to establish if you can put in a '.$variable.' or not.';
 

coacalli

New Member
Messages
10
Reaction score
0
Points
0
Thanks for all your answers and i can asure you that i have tryed all your points, but unfortunatelly i'm afraid i'm not making my self clear about what i want.

when we use the include(something) method the page printos out the content of the included file, on the other hand if we use it directly as a variable value ir returns a numeric value that tells us if the file was loaded or not.

on the other hand, using the single quotation marks on the html is an interesting solution to the backslashing problem, but it still makes mandatory to turn the page into php code instead of plain html. So it solves just a tiny part of the problem.


i'll try to be a bit more clear about what i try to do.

We all know how to make a mailing system, no secrets there, but when it comes to make a format that fits the client specifications.. that's why I want to solve this puzzle.

I've found my self that on PHP you can make almost everything a variable, even variable names can be variable for what i know.

so, what i want is to make the content of a HTML page the value of a variable, no print it out or include it as part of the output but only include the contents as part of the prosses.

when ever i use the include(something) method it displays the content of my HTML file, and there's no use for it on a page that only processes information.

so, maybe you could say i'm alzy, or too obssesed with this point, but i don't want to have to write an html page, then turn it into php every single time i have to make a change on it (maybe i am lazy or even crazy).

PLease, can any body help?
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
you can use heredoc to define your html variables

EDIT:

Oh so you want a templating system!!!

I've created one, if you want. It's very simple, and it's easy to use. PM if you are interested.
 
Last edited:

coacalli

New Member
Messages
10
Reaction score
0
Points
0
Interesting aproach xav, but maybe i'm not that versed on the use of heredoc, correct me (pleasE!) if i'm wrong, but doesn't it woks only to printout large amounts of text with out the need of scaping characters?

if this is the case, is not working for me cos what i need is the code on my HTML be the value for a variable, thus i can change that file when ever i want and not having to change the code on the mailer.
 

kbjradmin

New Member
Messages
512
Reaction score
2
Points
0
PHP:
<?php
$code = fopen(filename, "r");
echo $code;
?>

i think that's right, check it first.
 
Top