Jump to content

PHP parsing word html


grinel

Recommended Posts

Hey Guys

I have a website where people are allowed to enter html code. its works fine with regular html, but some people are copying stuff from MSword and pasting it into my program.

When i echo the field from the database, it gets a parse error because there are codes in the html such as <?, ; and stuff like that, that relates to php.

Is there a way i can parse these html code before i echo it from PHP?

Thanks in advance
Link to comment
Share on other sites

Indeed - you need to use a preg_replace on the submitted html to remove bits that it doesn't like - using strip tags would stop the php but also the html....

try something like...

[code]
<?php
$lookfor = array(
'/(<\?)(?!>)*/',
'/microsoft/')

$replace = array(
'',
'midocresoft');

$string = preg_replace($lookfor,$replace, $_POST['string']);
?>[/code]

The ordering of the elements in the array ARE important $lookfor[2] will be replaced by $replace[2]...
Link to comment
Share on other sites

Thanks for the reply

but the horses are out the gate, meaning i have about 3,000 users who have enterered html code. some are funky others are not. i can do this for the new entries..

I am planning to remove allowing html entry.. what can i do to the already entered html code?

is there a way to display the output of the html code in a text box when the user edit his post and then i can save the text version when they submit.

Link to comment
Share on other sites

You can try this.
Just in and out of php
for instance
<?php
functions and other stuff
?>
then you can enter your html here
<?php
then php
?>
this will allow your html to come through without having errors for the php information, and if you are talking about people are trying to input php like that, you would have to create a bigger program to allow people to put in there own php for output, like a mini-browser or something, what "exactly are you having a problem with, or refering too.

ALso give me a url for the website, somethign I can look at, and point me to the pages you are having the trouble and also show me to some of your source code, remember I can't see the php in view source so I need to look at that as well, but don't take long, I have to get back to studying soon.

also look at this here, and see if it is of any help with this specific problem
[a href=\"http://www.michelf.com/projects/php-markdown/\" target=\"_blank\"]http://www.michelf.com/projects/php-markdown/[/a]
Link to comment
Share on other sites

You can do this on the page that displays their posts rather than on the actual script that enters the html into the database.

This would allow you to filter the posts retrospectively - also you could set a cronjob up that will just loop through all the posts and do this for you so you have all the 'old' post corrected.

The last suggestions of doing the retorspective updates means you could then just have the script entering posts into the database performing this job - much more efficient.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.