SitePoint Sponsor |
|
User Tag List
Results 1 to 12 of 12
-
Oct 8, 2007, 01:51 #1
- Join Date
- Aug 2007
- Location
- Australia
- Posts
- 33
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Assign varaible to html outside of <?php ?>
Hi, I was wondering if it is possible to do something like this:
PHP Code:<html>
<?php
var =
?>
<lots of html>
<?php
;
?>
Since I know you can wrap html inside of while(){} structures...
Thanks
-
Oct 8, 2007, 02:09 #2
- Join Date
- Oct 2007
- Location
- Islamabad
- Posts
- 11
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
it is not possible in php because after assign operator php looks for the value and value should be either integer,string,char,array or object with terminator ";" at end like that
$var = '<lots of html>';
so if you want to wrap html code inside php you should write it in string format by using single or double quotes around itTaufeeq ur Rehman
Software Engineer
Skills: PHP,MySQL,JavaScript,Ajax
-
Oct 8, 2007, 02:12 #3
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Oct 8, 2007, 02:57 #4
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
And if you want to remain the HTML in the screen and get the buffer contents in a variable then do like this:
PHP Code:<?php
ob_start();
?>
<html tags>
<?php
$var = ob_get_contents();Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Oct 8, 2007, 03:04 #5
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Or, if there is ALOT of HTML, you could store it in a separate file. Then, use something like:
PHP Code:<?
$var = file_get_contents("lotsofhtml.html");
?>Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Oct 8, 2007, 06:12 #6
- Join Date
- Aug 2007
- Location
- Australia
- Posts
- 33
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hhmm ok thanks for all your replies
I've thought of another method that works for me, since all I want to do is place the html in a seperate place to where it is defined. I used the following:
PHP Code:<?php
function get_html(){
?>
<html>
<?php
}
?>
-
Oct 8, 2007, 20:05 #7
- Join Date
- Aug 2007
- Posts
- 365
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try
PHP Code:<?
$string = <<<ENDOFSTRING
<html>
<head>
<title></title>
</head>
<body>
.
.
.
</body>
</html>
ENDOFSTRING;
?>
-
Oct 8, 2007, 21:10 #8
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Oct 9, 2007, 01:12 #9
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
However, it cannot be used if you want to modify it or use it in any way, other than echoing it.
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Oct 9, 2007, 01:18 #10
- Join Date
- Aug 2007
- Location
- Australia
- Posts
- 33
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
True, and it also gets really annoying when you try to pass variables contained within it, to other functions
The buffer output works really well
-
Oct 9, 2007, 01:41 #11
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
But again, I would find it better to put the HTML in a separate file - that way it's easier to manage, the PHP script looks tidier, and you can put it all into a variable through file_get_contents()
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Oct 9, 2007, 01:57 #12
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
Bookmarks