...

View Full Version : How do I Parse the HTML?



Hyp3r grunt
12-22-2007, 11:21 PM
I think 'parse' is the term used that means 'make happen' but I'm not sure if parsing the HTML is what I want to do.

I have a system where you can submit a news post and have it go into a database. There is a page called 'submitnews.html' - this is the page with the form to put in the information. When the information is put in and 'Submit' is hit this page comes into action:


<?php
ob_start();
session_start();
if(!session_is_registered(myusername)){
header("location:stafflogin.html");
}
$path = './';
include($path . 'above.inc'); ?>

<title>Website - Submit News</title>

<?php include($path . 'below.inc'); ?>

<div id="main">
<h1>Error</h1>

<?php
$dbhost = 'host';
$dbuser = 'username';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'database';
mysql_select_db($dbname);

$title = $_POST['title'];
$category = $_POST['category'];
$story = $_POST['story'];
$healthy = array("<", ">", "\"", "\'", "&");
$yummy = array("&lt;", "&gt;", "&quot;", "'", "&amp;");
$dem = str_replace($healthy, $yummy, $story);
$itemdescription = "$dem";
$date = $_POST['date'];

$id = mysql_real_escape_string((int)$_GET['id']);
$query = "SELECT `id`
FROM `tablename`
ORDER BY `id` DESC
LIMIT 0 , 1";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

$blabla = "SELECT `id`
FROM `tablename`
ORDER BY `id` DESC
LIMIT 0 , 1";
$mesult = mysql_query($blabla);
$wow = mysql_fetch_array($mesult);

$sql = "insert into anothertable (title, category, story, date, permalink, itemlink, itemdescription, author) values ('$title', '$category', '$story', '$date', '<a href=\"/news.html?id={$wow['id']}\">Permalink</a>', 'http://www.halonirvana.com/news.html?id={$row['id']}', '$itemdescription', 'Hyp3r Grunt')";
$result = mysql_query($sql, $conn) or die(mysql_error());

$magic = "INSERT INTO tablename (id) VALUES ('')";
$result = mysql_query($magic, $conn) or die(mysql_error()); ?>

<?php mysql_close($conn);
header("location:submitnews.html");
ob_end_flush();
?>

</div>

<?php include($path . 'furtherbelowalternate.inc'); ?>

The problem is that the item description variable is then picked up in an RSS 2 feed. It has all the html code still in it, how do I make the html 'happen'.

SeeIT Solutions
12-23-2007, 12:26 AM
I'm not exactly sure what you wanted, but try this and see if it acheives what you want.

Change


$itemdescription = "$dem";

to


$itemdescription = addslashes($story);

Hyp3r grunt
12-23-2007, 09:47 PM
I got it working, I did what you told me to in a way and I also used 'htmlspecialchars'. Everything is good now, thanks for your help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum