homepage Welcome to WebmasterWorld Guest from 54.211.68.132
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Can PHP3 edit HTML ?
kapow




msg:1260046
 2:50 pm on Oct 19, 2001 (gmt 0)

Is it possible to write a php3 script that:
1. Reads an html page.
2. holds html code as variables.
3. holds text for editing in a simple form.
4. Re-writes the html page with the old code and new text.

e.g. Could the script look for special tags in the html page like <---xyz--->

something like this:

HTML PAGE TO EDIT
<---html code start--->
code here
<---html code end--->

<---text start--->
text here
<---text end--->

<---html code start--->
code here
<---html code end--->

<---text start--->
text here
<---text end--->

<---html code start--->
code here
<---html code end--->

I am new to php, can anyone point me in the right direction as to the kind of commands to do this?

 

Slade




msg:1260047
 3:41 pm on Oct 19, 2001 (gmt 0)

Don't quite follow you. Do you want the script to save the updated code back to the server? Or just display it to the user?

The work I've done recently has been laid out such:

/public_html/index.php
This file contains less than 10 lines, sets a few variables, and "includes" a template page. There is either a page like this for every page of the site, or some "?" trickery to make it show the right page at the right time.

/content/layout.txt
This is my layout template for the site. All pages that follow the basic form start from this. It is mostly html, with a <?php include($this-pages-content-file); ?> in the middle, and <?php echo $this-pages-title; ?> at the top.

/content/index.txt
This page, for example, would have the content for the index page. This is an html fragment page that holds the guts for the page. There is another page like this for every page on the site.

kapow




msg:1260048
 3:58 pm on Oct 19, 2001 (gmt 0)

I want to make a php script that allows my clients to update the text on their web pages.
The php page (script) will:

1. Read an html page.

2. Present a form with the text content in text boxes for the client to edit and hit the 'update' button.

3. Re write the html page with the new text.

I would like to avoid 'includes' as I have heard that php pages can get a lower rank on SEs.

My client will go to his secure 'Update tool' (php) - which rewrites their html pages.

ggrot




msg:1260049
 4:26 pm on Oct 19, 2001 (gmt 0)

Do a touch of research on apache .htaccess files and figure out how to make .htm or .html files run php on command. I don't remember the exact syntax off the top of my head.

On the other hand, its actually a good idea to do things the way you were mentioning (with static pages that are changed by php) since that will protect you from having too much processor usage in the event of high traffic. What you would need to do is open the file in question for reading using:
$file_index = fopen($filename,'r')
I think you then read it into a string with:
string buffer = fread(file_index, sizeof($file_index))
then close your file:
fclose($file_index)
Then, I think you can scan through the string looking for the specific location of a substring using:
strstr($needle,$haystack)
Once you found the beginning and ending index of the string you want to replace, use
substr(beginning,end)
to extract the string and output it in the form.
Then when the user submits his input, you just open your file for writing:
fopen($filename,'w')
and start dumping text into it.

Its actually quite a pain to write the script, but if you over generalize it, you'll only have to do it once.

circuitjump




msg:1260050
 5:20 pm on Oct 19, 2001 (gmt 0)

I found some code that did exactly what you want to do.

Go to [sourceforge.net...]

you will most likely find what you need.

kapow




msg:1260051
 5:46 pm on Nov 23, 2001 (gmt 0)

Well I've got my script now and it works.
I have to add these tags either side of editable text:
<!--edit "Name of the label"--> <!--end-->

Will this affect SEO? If I have these tags inside <H1> or <P> tags

I know I can't expect great SEO with my clients updating their own pages (I give them some basic lessons). I just want to know if say Google would get upset about such tags within <H1> or <P> tags

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved