Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting a .htm page with PHP 1

Status
Not open for further replies.

DeepBlerg

Technical User
Jan 13, 2001
224
AU
I have a php page where the user uploads (through a form) a .htm page which gets included into another page. The problem is the uploaded .htm page has text in it that I want to remove, like <HTML><HEAD><BODY> etc etc.

Is there a way in PHP to remove certain lines of html from a page when it's uploaded? Thanks in advance.
 
On second thought, I think it would just be easier to do a string replace on the page before you display it... just read the file into a string, then do this:
Code:
// Fill this array with any thing you want to remove
Code:
$bad_tags = array(&quot;
Code:
<HTML>
Code:
&quot;, 
                  &quot;
Code:
<TITLE>
Code:
&quot;, 
                  &quot;
Code:
</TITLE>
Code:
&quot;, 
                  &quot;
Code:
</HTML>
Code:
&quot;
                  );
$page_source = str_replace($page_source, &quot;&quot;, $bad_tags);

This is the quick and easy way to do it... i dunno how many tags you plan on parsing and this was easier than anything else.

It may not be as fancy as what you were hoping for, but hey, it works, doesn't it? LOL

Good luck! -gerrygerry
Go To
 
hello

u can use strip_tags function.

$text = strip_tags($text,[allowablwe html tags]);

but beware of the fatc that it will strip everything between the tags < and > so it might be some text by the user like <here is my text>

hope it will help u

spookie
 
Very similar to my solution spookie, but I think my solution would be better as far as preventing any accidental deletes.

Plus, it's easier to enter the tags DeepBlerg wants to remove than it is to write the tags to keep!

Good luck! -gerrygerry
Go To
 
yes gerrygerry
i completely agree with u.
just posted the message for the anothere alternative thats all.

cheers

spookie
 
yes gerrygerry
i completely agree with u.
just posted the message for the another alternative thats all.

cheers

spookie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top