PDA

View Full Version : Removing info from a flat file?



splintercell!
12-07-2005, 04:44 PM
Ok do you know how to remove info from a flat file and display it on a webpage (like cutenews).

:Blob
12-07-2005, 04:45 PM
Like show news on cutenews or i dont know what ya mean

splintercell!
12-07-2005, 04:54 PM
yup. I have written some stuff from a form through to a flat file txt database all I need to know is how to display it on a page..

:Blob
12-07-2005, 04:58 PM
Hmm

If you have a news.txt file, i think you might have to make it point to that

:Woof
12-07-2005, 05:08 PM
Why not view the cutenews file? and see if you find the correct code? :)

:Blob
12-07-2005, 05:11 PM
Why not view the cutenews file? and see if you find the correct code? :)

Tried it and it only comes up with the news entered in text...

Tomm
12-07-2005, 05:18 PM
no u have to use the file on your computer it wont work if u try and view the sorce

:Blob
12-07-2005, 05:21 PM
Ok then

Quite a long code




<?PHP

error_reporting (E_ALL ^ E_NOTICE);

$cutepath = __FILE__;
$cutepath = preg_replace( "'\\\show_news\.php'", "", $cutepath);
$cutepath = preg_replace( "'/show_news\.php'", "", $cutepath);

require_once("$cutepath/inc/functions.inc.php");
require_once("$cutepath/data/config.php");

//----------------------------------
// Check if we are included by PATH
//----------------------------------
if($HTTP_SERVER_VARS["HTTP_ACCEPT"] or $HTTP_SERVER_VARS["HTTP_ACCEPT_CHARSET"] or $HTTP_SERVER_VARS["HTTP_ACCEPT_ENCODING"] or $HTTP_SERVER_VARS["HTTP_CONNECTION"]){ /* do nothing */ }
elseif(eregi("show_news.php", $PHP_SELF)){
die("<h4>CuteNews has detected that you are including show_news.php using the URL to this file.<br>
This is incorrect and you must include it using the PATH to show_news.php</h4><br>Example:<br>
this is <font color=red>WRONG</font> :&nbsp;&nbsp; &lt;?PHP include(\"http://yoursite.com/cutenews/show_news.php\"); ?&gt;<br>
this is <font color=green>CORRECT</font>:&nbsp;&nbsp; &lt;?PHP include(\"cutenews/show_news.php\"); ?&gt;<br>
<br><BR>// <font size=2>if you think this message shouldn't be shown, open show_news.php and delete it from there</font>");
}
//----------------------------------
// End of the check
//----------------------------------

if(!isset($subaction) or $subaction == ""){ $subaction = $POST["subaction"]; }

if(!isset($template) or $template == "" or strtolower($template) == "default"){ require_once("$cutepath/data/Default.tpl"); }
else{
if(file_exists("$cutepath/data/${template}.tpl")){ require_once("$cutepath/data/${template}.tpl"); }
else{ die("Error!<br>the template <b>".htmlspecialchars($template)."</b> does not exists, note that templates are case sensetive and you must write the name exactly as it is"); }
}

// Prepare requested categories
if(eregi("[a-z]", $category)){
die("<b>Error</b>!<br>CuteNews has detected that you use \$category = \"$category\"; but you can call the categories only with their <b>ID</b> numbers and not with names<br>
example:<br><blockquote>&lt;?PHP<br>\$category = \"1\";<br>include(\"path/to/show_news.php\");<br>?&gt;</blockquote>");
}
$category = preg_replace("/ /", "", $category);
$tmp_cats_arr = explode(",", $category);
foreach($tmp_cats_arr as $key=>$value){
if($value != ""){ $requested_cats[$value] = TRUE; }
}

if($archive == ""){
$news_file = "$cutepath/data/news.txt";
$comm_file = "$cutepath/data/comments.txt";
}else{
$news_file = "$cutepath/data/archives/$archive.news.arch";
$comm_file = "$cutepath/data/archives/$archive.comments.arch";
}

$allow_add_comment = FALSE;
$allow_full_story = FALSE;
$allow_active_news = FALSE;
$allow_comments = FALSE;

//<<<------------ Detarime what user want to do
if( $CN_HALT != TRUE and $static != TRUE and ($subaction == "showcomments" or $subaction == "showfull" or $subaction == "addcomment") and ((!isset($category) or $category == "") or $requested_cats[$ucat] == TRUE) ){
if($subaction == "addcomment"){ $allow_add_comment = TRUE; $allow_comments = TRUE; }
if($subaction == "showcomments") $allow_comments = TRUE;
if(($subaction == "showcomments" or $allow_comments == TRUE) and $config_show_full_with_comments == "yes") $allow_full_story = TRUE;
if($subaction == "showfull") $allow_full_story = TRUE;
if($subaction == "showfull" and $config_show_comments_with_full == "yes") $allow_comments = TRUE;

}
else{
if($config_reverse_active == "yes"){ $reverse = TRUE; }
$allow_active_news = TRUE;
}
//----------->>> Detarime what user want to do

require("$cutepath/inc/shows.inc.php");
if($_GET['archive'] and $_GET['archive'] != ''){ $archive = $_GET['archive']; } // stupid fix ?
unset($static, $template, $requested_cats, $category, $catid, $cat,$reverse, $in_use, $archives_arr, $number, $no_prev, $no_next, $i, $showed, $prev, $used_archives);
?>
<!-- News Powered by CuteNews: http://cutephp.com/ -->


Edit that

Tomm
12-07-2005, 05:27 PM
lol i think this is one for mentor :D

:Blob
12-07-2005, 05:42 PM
Me to

*Opens mentors door and waits*

Tomm
12-07-2005, 05:46 PM
mentor come here boy *whistles*

:Blob
12-07-2005, 05:48 PM
*Gets frizbe and throws*

Tomm
12-07-2005, 05:50 PM
lol hes offline we will have to wait :(

splintercell!
12-07-2005, 06:00 PM
Ok your all super spaming and being stupid "? I have looked through other files but I cant seem to find a way of doing it if you dont know then dont answer dont just start spamming.

:Blob
12-07-2005, 06:01 PM
Sorry

Umm

If the news goes to news.txt and that updates, shouldnt show_news.php point to news.txt

splintercell!
12-07-2005, 06:03 PM
yes but cutenews is very different it contains lots of templates and other files so its not clear where it is "/

Tomm
12-07-2005, 06:32 PM
there must be some connector somewhere but where mmm...

Mentor
12-07-2005, 07:04 PM
Ok do you know how to remove info from a flat file and display it on a webpage (like cutenews).
Ok, so you mean link editing a line in a flat file, or displaying the data from the flat file?

for dispay most important things is the
file();
command, wich splits the lines and turns them in to an array.

Say to get flat file bob.txt

$arrayvariable = file("bob.txt");

Then split the varible down again

depedning on what your useing a seportaors (cute news use's |/\| i usealy use || thogh

foreach($arrayvariable as $Key => $Val)
{
//explode that data into a array
$info[$Key] = explode(",", $Val);

}

now the $info varible contains both arrays, wich you can output via a loop

for($num = 0; $num<sizeof($arrayvariable) + 1; $num++)
{
echo $info[$num][0];

}

This would dispaly the the first entry of everu line, since its changing the arry var while looping threw them all.

to show second bit $info[$num][1];

etc etc etc

if you follow?

the flat file struture in the exsample would be

user1||stuff||morestuff||
user2||stuff2||morestuff2|

etc etc

splintercell!
12-07-2005, 07:18 PM
*gives mentor a gold star* Thanks :D Helped me alot none of the php sites seems to have it, Ive done it in mySQL before but I wanted to use a flat file to see how it works :) Thanks.!

Want to hide these adverts? Register an account for free!