Web Hosting Talk







View Full Version : Parsing HTML page and adding tags at runrime


effusionx1
07-30-2005, 06:17 PM
Hi there,

I have a PHP book and have leant on many other resources to try and answer my question but without success.
As VBForums always tends to help me out with my Visual Basic problems - I thought I might try the same for PHP.

The Problem

I have a HTML document which has a table in it.
The table has 2 columns and 2 rows.
In the first column of each row is a short piece of text denoting the progress of the php script. Is it possible for PHP to be able to add a tick image to the second column of each row when the associated process has passed.
(I would of course use the img src tag).
However, how can I get PHP to add this tag at runtime and in the right cell of the table.

Many thanks,

Jord

fastduke
07-30-2005, 08:42 PM
What?

You do know that php outputs the html?
php can decide whenever you add html(that's kinda what it's for).

If I understand you correctly... You are trying to do something like add someting if the conditions are right? For example a message board displays a different icon to indicate that the post has a new reply. Is this what you are getting at?

effusionx1
07-30-2005, 09:20 PM
Kind of, yes. I know PHP can add HTML to a document but the table will be hard-coded into the HTML document before the PHP script even starts. I then want php to somehow add an img src tag to this table at runtime of the php script.
So I need PHP to:

a) Find the right cell of the table
b) Print the img src tag to it

How do I have PHP parse the HTML document for this particular cell and then print inside of that cell.
I am not trying to add something 'when the conditions ae right' the img src tag should be added whenever a piece of code has been passed.

I hope that makes my problem clearer...

fastduke
07-30-2005, 10:07 PM
You are thinking things backwards.

Either you need to embed the php into the html or you need to have php do all of it. I t doesn't seem to make sense to have php local parse local html (data mining of some sort I might understand).

just as an example if you can't embed php into html just do a 'page.php':

<!-- this is a php page but I can use html anywhere I want -->
<html><head><title>This</title></head>
<body>
Stuff here

<? // PHP stuff goes here

$php_is = "Your friend for writing html";

// end php here
?>

</body>
</html>

xelhosting
07-31-2005, 01:44 AM
You probably need templating. Search and learn some template engines like smarty or phplib

Burhan
07-31-2005, 07:21 AM
Actually, you don't need templating. If I understand your problem correctly, you want PHP to update a page as its running -- sort of displaying a live counter or status bar. Is this correct? If so -- you probably want to explore output buffering.

effusionx1
07-31-2005, 07:37 AM
Originally posted by fyrestrtr
Actually, you don't need templating. If I understand your problem correctly, you want PHP to update a page as its running -- sort of displaying a live counter or status bar. Is this correct? If so -- you probably want to explore output buffering.

Yeah, thats right, but I don't know how to physically "place" the tick (progress) image in the correct part of the HTML document. ie. The table cell...

Burhan
07-31-2005, 07:59 AM
You'll need to use javascript if you want the update to be 'live' without a server request. PHP only runs on the server, so you need a client-side language such as javascript.