Page 1 of 1

Replace HTML with PHP?

Posted: Wed Apr 16, 2008 10:18 pm
by Taylor589
Hi. I'm looking for a way to use PHP to replace some html within the same document. I'm using a CMS that only allows php in a specific place at the end of a document, so I need to somehow get the html before the php tags into a string, perform some replacements, and overwrite the html with the new stuff.

Is this read/overwrite even a possibility with php? Thanks for any help.

Re: Replace HTML with PHP?

Posted: Wed Apr 16, 2008 10:43 pm
by JellyFish
If the CMS your are using doesn't allow you to place the php where you want in the page, then I'd suggest you use another tool for editing your web pages. I usually use a text editor such as Aptana(My choice), Crimson Editor or Textpad.

With a text editor you can easily drop into the pages source code and place php where you want it.

As far as what you're saying I don't think it's possible. That is if I understand what you're saying. Let me illustrate what it is I think you might be saying.

Code: Select all

 
<html>
<!-- html content etc. -->
</html>
<?php
//php code
?>
 
Sense the html above the php is considered server output I don't think that there is a way for the php parser to recognize this.

From what I know of, I don't think there is a way to make the html into a php string.

Re: Replace HTML with PHP?

Posted: Wed Apr 16, 2008 10:59 pm
by Taylor589
I was afraid of that answer...

Unfortunately, I can't just edit the html and insert php, since the html pages I would be working with are the product of everything a CMS does. In essence, the CMS uses it's own php behind the scenes to produce a document, and allows me to run a php script a second time before the document is served.

The CMS does allow javascript within the html templates, so my only option might be bulky client-side processing to replace a few string instances.

(It's definitely not my choice of CMS.)

Re: Replace HTML with PHP?

Posted: Wed Apr 16, 2008 11:45 pm
by JellyFish
What is it in the HTML document that you would like to change with php, that you can't with the CMS?

Re: Replace HTML with PHP?

Posted: Thu Apr 17, 2008 12:04 am
by Taylor589
The reason's for html replacement are a long story, but let's just say there's no way around it. If it's not possible with php, I'll have to resort to javascript.