Replace HTML with PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Taylor589
Forum Newbie
Posts: 3
Joined: Wed Apr 16, 2008 10:08 pm

Replace HTML with PHP?

Post 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.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Re: Replace HTML with PHP?

Post 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.
Taylor589
Forum Newbie
Posts: 3
Joined: Wed Apr 16, 2008 10:08 pm

Re: Replace HTML with PHP?

Post 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.)
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Re: Replace HTML with PHP?

Post by JellyFish »

What is it in the HTML document that you would like to change with php, that you can't with the CMS?
Taylor589
Forum Newbie
Posts: 3
Joined: Wed Apr 16, 2008 10:08 pm

Re: Replace HTML with PHP?

Post 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.
Post Reply