By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 697 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

Embed lots of html code in php & construc objects in php

P: n/a
Hi folks,

I have a php file, it contains just a few php codes. The php codes I
need to use is to construct an object, and use it several times, from
html head until the last line of html code.

I know I can construct the same object (I am using php5) several
times, something like $object = new $class, and use several <?php
$object->functionX ? ... <?php $object->functionZ ? to include
php code in html code.

However, to construct this object I have to call a remote server, and
rely on its response, which is a bit slow. To construct it several
times takes even more time, and I do not like that.

So my questions are :

1) How can I embed a big chunk of html code in php without using
something like echo "<a href=\"aaa.html\">" all the time

2) Can I just construct an object one time and use it in different <?
php ... ?blocks?

Thanks,

May 17 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ming wrote:
Hi folks,

I have a php file, it contains just a few php codes. The php codes I
need to use is to construct an object, and use it several times, from
html head until the last line of html code.

I know I can construct the same object (I am using php5) several
times, something like $object = new $class, and use several <?php
$object->functionX ? ... <?php $object->functionZ ? to include
php code in html code.

However, to construct this object I have to call a remote server, and
rely on its response, which is a bit slow. To construct it several
times takes even more time, and I do not like that.

So my questions are :

1) How can I embed a big chunk of html code in php without using
something like echo "<a href=\"aaa.html\">" all the time

2) Can I just construct an object one time and use it in different <?
php ... ?blocks?

Thanks,
Ming,

You can go in and out of PHP at any time, i.e.

.... header info ...

<html>
Lots of html code here
<?php
// Put a bunch of PHP in here
?>
More and more html
<?php
// Some more PHP
?>
</html>

You can also use heredoc syntax
<(http://us2.php.net/manual/en/language.types.string.php)>, i.e.

<?php
echo <<EOT
Now is the time
for all good men
to come to the aid
of their party.
EOT
?>

And yes, you can use the same object in as many PHP blocks as you want,
as long as it's on the same page. Objects do not disappear when you
leave a PHP block; rather they go away at the end of the page.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 17 '07 #2

P: n/a
Ming wrote:
2) Can I just construct an object one time and use it in different <?
php ... ?blocks?
Well yes -- that's kind of the point. You create an object and then you
use it as many times as you like.

Also Google for: PHP Singleton Design Pattern

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
May 17 '07 #3

P: n/a
Ming wrote:
Hi folks,

I have a php file, it contains just a few php codes. The php codes I
need to use is to construct an object, and use it several times, from
html head until the last line of html code.
All php block share the same scope, so it would be enough to construct
the object only once:

<?php $myObject = new Foo(); ?>
html here
<?php $myObject->bar(); ?>
more html
<?php $myObject->baz(); ?>
--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
May 17 '07 #4

P: n/a
On May 17, 7:24 am, Ming <minghu...@gmail.comwrote:
Hi folks,

I have a php file, it contains just a few php codes. The php codes I
need to use is to construct an object, and use it several times, from
html head until the last line of html code.

I know I can construct the same object (I am using php5) several
times, something like $object = new $class, and use several <?php
$object->functionX ? ... <?php $object->functionZ ? to include
php code in html code.

However, to construct this object I have to call a remote server, and
rely on its response, which is a bit slow. To construct it several
times takes even more time, and I do not like that.

So my questions are :

1) How can I embed a big chunk of html code in php without using
something like echo "<a href=\"aaa.html\">" all the time

2) Can I just construct an object one time and use it in different <?
php ... ?blocks?

Thanks,
How about including it? see http://uk.php.net/manual/en/function.include.php

May 17 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.