PHP - Split Up Large Html File Based On Html Tags?
Hey guys,
I'm a total newbie here, and just about as a new to php. My issue: I have a very large .html file that contain multiple articles (I actually have a few of these, but we'll start with one for practicality). The article titles are all wrapped in <h2> tags, there are 10 articles in one file. The articles are very simple, just a title wrapped with <h2> and then a few paragraphs wrapped in <p> tags. What I want to know how to do: I want to know if there's a way to open that file, and have each article saved as it's own .html or .txt document (the title & following paragraphs of each article). Ultimately taking my 1 large file, and creating the subsequent 10 smaller files from the articles inside of it. I am having trouble explaining this in text so I'll try to illustrate: I have "Articles.html" - which contains (article1,article2,article3.. ..article10) I want to split "Articles.html" and create "Article1.html", "Article2.html", "Article3.html", etc. Is that possible? Or am I looking at something far more complex than I can imagine at this point - perhaps something I'd be better off doing by hand? Ultimately I intend to stick all these articles into a database, but that's the 2nd part of what I want to do (and I think will be the easier of the tasks). Let me know if you need any additional information in the event my description above is unclear... I simply am having issues figuring out how to separate out the text into individual articles. Similar TutorialsSay I have the following text stored in a MySQL database... Code: [Select] <b>Classic Quote from movie</b> and I retrieve it into a variable called $text, how do I properly echo that so that it keeps the bold tags and actually display the text "Classic quote from movie" in BOLD? I'm doing something wrong somewhere along the line (simply doing "echo $text;") because it displays on the page as... Code: [Select] <b>Classic Quote from movie</b> Instead of... Classic Quote from movie Any info on properly storing and echoing back HTML would be very appreciated. Yes, it's a homework assignment. No, I'm not trying to cheat, so pointing me somewhere is better than just feeding me code, like, "look up how to blah blah" or tell me what I've got wrong? I'm trying to parse a text file of the constitution, add header and <p> tags depending on the first word of the paragraph, then print to an html page. I know I'm supposed to create a function that will return a paragraph, and another function that will return the first word of a paragraph. This is my code, and it completely does not work (obviously I've not included the external html tags) <?php // Opens the constitution text file. $const = fopen("constitution.txt","r"); //Returns an entire paragraph function getParagraph($myfile) { while (!feof($myfile)){ $line = file_get_contents($myfile); $paragraph = explode("\n",$line); } return $paragraph; } //Returns the first word of a paragraph function getFirstWord($myfile) { $pg = getParagraph($myfile); $word = explode(" ",$pg); Return $word[0]; } // Runs through some if statements to determine the tags to use if (getFirstWord($const) === "Article"){ echo "<h2> getParagraph($const)</h2>"; } elseif (getFirstWord($const) === "Section"){ echo "<h3> getParagraph($const)</h3>"; } elseif (getFirstWord($const) === "Amendment"){ echo "<h3> getParagraph($const)</h3>"; } elseif (getFirstWord($const) === "We the People"){ echo "<em> getParagraph($const) </em>"; } else{ echo "<p> getParagraph($const) </p>"; } fclose($const); ?> Hey Guys. I am trying to write to an HTML and attach that file for an efax API. One of the file types they accept is HTML, but it has to be in a <base> tag format. I am a little confused on how to do that. I tried to use fopen with the base tag but it didn't seem to work for me. I got the following error
Warning: fopen(<base a href='96401.html'></base>) [function.fopen]: failed to open stream: No such file or directory
Ideally what I am trying to accomplish is creating a file that just says 96401.html.
Below is the code that I have tried it with. Any help would be really appreciated!!!
$orderFile = "<base a href='".$id.".html'></base>"; // File name to be created. order id is used as a file name e.g. 123456.html //$fh = fopen($orderFile, 'w') or die("can't open file"); // Create and Save the writeable File //fwrite($fh, $order_information); // Write email contents to created file. Hi Still very new to PHP but getting some good use out of it with includes. I'm currently using this code to check the file name of the page and then give the corresponding anchor tag a class of active in order to style my main menu. This is all working for most of my pages but my problem is that I now have multiple files called index.php one in the root of my site and some are in folders. Is there any way around this issue? Can PHP check to see if its the index file in the root of the site or is there a better way. I suppose I could create a second variable in the index file in my root ie my home page and then check to say if the current page is called index and has the variable of home but how would I write this? My code Code: [Select] $currentPage = basename($_SERVER['SCRIPT_NAME'], '.php'); <li><a href="/" <?php if ($currentPage == 'index') {echo 'class="active"';} ?>>Home</a></li> i need help here..i want to echo a lage code of html but it is giving me problems..i know it will hv to do with the syntax but am confused on how to go about it..below is the php code and the html codes Code: [Select] <?php include"header.php"; session_start(); if(isset($_POST['submit'])) { $log=mysql_real_escape_string($_POST['mail1']); $pas=($_POST['pass1']); if($log=='' || $pas=='') { echo "Please supply your Username(your email address) and your password"; } else { $sel="SELECT user_name,userID FROM user WHERE (user_email='$log') AND (user_password='$pas')"; $ok=mysql_query($sel) or die(mysql_error()); if(mysql_num_rows($ok)==0)echo"Wroung Username or Password used,Please try again"; else { while($row=mysql_fetch_array($ok)) { $_SESSION['userID']=$row['userID']; $_SESSION['user_name']=$row['user_name']; $_SESSION['user_date']=$row['user_date']; echo $_SESSION['user_date']=$row['user_date']; echo"this is where i want to put the html codes so that the user_name appears on the page".$_SESSION['user_name']; } } } } mysql_close(); ?>this is the html codes Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta name="Description" content="Information architecture, Web Design, Web Standards." /> <meta name="Keywords" content="your, keywords" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="Distribution" content="Global" /> <meta name="Author" content="Erwin Aligam - ealigam@gmail.com" /> <meta name="Robots" content="index,follow" /> <link rel="stylesheet" href="images/PixelGreen.css" type="text/css" /> <title>Planetafric</title> </head> <body> <!-- wrap starts here --> <div id="wrap"> <div id="header"><div id="header-content"> <h1 id="logo"><a href="index.html" title="">speak<span class="gray">out</span></a></h1> <h2 id="slogan">The Revolution is now...</h2> <!-- Menu Tabs --> <ul> <li><a href="index.html" id="current">Home</a></li> <li><a href="index.html">News</a></li> <li><a href="index.html">Downloads</a></li> <li><a href="index.html">Support</a></li> <li><a href="index.html">About</a><li> </ul> </div></div> <div class="headerphoto"></div> <!-- content-wrap starts here --> <div id="content-wrap"><div id="content"> <div id="sidebar" > <div class="sidebox"> <h1>About this Website</h1> <p>Due to the injustice we face conitnualy in this nation WE (KTECHGROUP) have decided to stamp our feet against all this ills in our country..THE TIME IS NOW ..Stand against non avalabitlty of social amenities, stand against unemployment and stand against corruption.<img src="speakout_1.png"/></p> </div> <div class="sidebox"> <h1 class="clear">Sidebar Menu</h1> <ul class="sidemenu"> <li><a href="index.html" class="top">Home</a></li> <li><a href="#TemplateInfo">Template Info</a></li> <li><a href="#SampleTags">Sample Tags</a></li> <li><a href="http://www.styleshout.com/">More Templates...</a></li> <li><a href="http://www.4templates.com/?aff=ealigam">Premium Templates</a></li> </ul> </div> <div class="sidebox"> <h1>Sponsors</h1> <ul class="sidemenu"> <li><img src="watch.jpg"/></br><h3>Longinnes wrist watch forsale at reduced price</h3></li> <li><img src="htc.jpg"/><label>4templates</label</li> <li><a href="http://store.templatemonster.com/?aff=ealigam">TemplateMonster</a></li> <li><a href="http://www.fotolia.com/partner/114283">Fotolia.com</a></li> <li><a href="http://www.text-link-ads.com/?ref=40025">Text Link Ads</a></li> </ul> </div> <div class="sidebox"> <h1>Wise Words</h1> <p>"No man can live happily who regards himself alone; who turns everything to his own advantage. You must live for others if you wish to live for yourself."</p> <p class="align-right">- Seneca</p> </div> <div class="sidebox"> <h1>Support Speakout</h1> <p>If you are interested in supporting this work and would like to contribute, you are welcome to make a small donation through the <a href="http://www.styleshout.com/">donate link</a> on this website - it will be a great help and will surely be appreciated.</p> </div> <div class="sidebox"> <h1>Search Box</h1> <form action="#" class="searchform"> <p> <input name="search_query" class="textbox" type="text" /> <input name="search" class="button" value="Search" type="submit" /> </p> </form> </div> </div> <div id="main"> <div class="post"> <a name="TemplateInfo"></a> <h1> </h1> <p>Posted by <a href="index.html">Adetoye Oni</a></p> <p><strong>A weeping Eye</strong> is a free, W3C-compliant, CSS-based website template by <strong><a href="http://www.styleshout.com/">styleshout.com</a></strong>.<p align="left"><img src="soldier_crying.jpg"/></p align> This work is distributed under thel;kmbkl;;lsjljhl;hjklghl;kk;gjhflk;jfgkl;jflhjflkhlkkjgfklk Creative Commons Attribution 2.5 License</a>, which means that you are free to use and modify it for any purpose. All I ask is that you include a link back tohjsklvjksjkskjvskdv dhlkdhlshdlkjhdslkjhkljsdhjsdhjlghdsjhjkdshgjkdhjkshdjkhdsjkhdkjsjgdgl sddjgkldsjlkgdlkshgldhsgldhlghdlshgdlhgldhlkhdlkdkhdlkgdgd djkdjklgdjklgjdslkjdlksjkldsjkldsjlkdsjklgjsldkjgkldsgdsgjdklsgjsljgl\ksdjgjldkgj;ldsk\jglkdsg <a href="http://www.styleshout.com/">my website</a> in your credits.</p> <p>For more free designs, you can visit <a href="http://www.styleshout.com/">my website</a> to see my other works.</p> <p>Good luck and I hope you find my free templates useful!</p> <p class="post-footer align-right"> <a href="index.html" class="readmore">Read more</a> <a href="index.html" class="comments"><?php if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo"Comments:".$_SESSION['views']; ?></a> <span class="date">Nov 11, 2006</span> </p> </div> <h3>Comments:</h3> <table> <tr class="row-a"> <td class="first"><?php include"header.php"; $sql="SELECT *FROM post "; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['post_date']}"."</br>"; } ?></td> <td><?php include"header.php"; $sql="SELECT *FROM post "; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['post_content']}"."</br>"; } ?></td> </tr> </table> <h3>Post your comments here</h3> <form action='reply.php'method='post'> <textarea name="comment" id="content" style="width:400px;height:50px;background-color:#D0F18F;color:#000000;font:15px/20px cursive;scrollbar-base-color:#638E0D;"></textarea> <br /> <input class="button" type="submit"name="submit"value="submit" /> </p> </form> <br /> </div> <!-- content-wrap ends here --> </div></div> <!-- footer starts here --> <div id="footer"><div id="footer-content"> <div class="col float-left"> <h1>Site Partners</h1> <ul> <li><a href="http://www.dreamhost.com/r.cgi?287326"><strong>Dreamhost</strong> - Affordable & Reliable Webhosting</a></li> <li><a href="http://www.4templates.com/?aff=ealigam"><strong>4templates</strong> - Low Cost Hi-Quality Templates</a></li> <li><a href="http://store.templatemonster.com/?aff=ealigam"><strong>TemplateMonster</strong> - Best templates on the net!</a></li> <li><a href="http://www.fotolia.com/partner/114283"><strong>Fotolia</strong> - Free stock images or from $1</a></li> <li><a href="http://www.text-link-ads.com/?ref=40025"><strong>Text Link Ads</strong> - Easiest. Money. Ever.</a></li> </ul> </div> <div class="col float-left"> <h1>Links</h1> <ul> <li><a href="http://www.openwebdesign.org/">openwebdesign.org</a></li> <li><a href="http://www.opendesigns.org/">Opendesigns.org</a></li> <li><a href="http://www.pdphoto.org/">PDPhoto.org</a></li> <li><a href="http://www.alistapart.com">Alistapart</a></li> <li><a href="http://www.cssremix.com">CSS Remix</a></li> </ul> </div> <div crrlass="col2 float-right"> <p> © copyright 2006 <strong>Ktech group</strong><br /> Programme by: <a href="index.html"><strong>Adeleye Caleb</strong></a> Valid <a href="http://jigsaw.w3.org/css-validator/check/referer"><strong>CSS</strong></a> | <a href="http://validator.w3.org/check/referer"><strong>XHTML</strong></a> </p> <ul> <li><a href="index.html"><strong>Home</strong></a></li> <li><a href="index.html"><strong>Sitemap</strong></a></li> <li><a href="index.html"><strong>RSS Feed</strong></a></li> </ul> </div> </div></div> <!-- footer ends here --> <!-- wrap ends here --> </div> </body> </html> Thanks in advance and this is the html We have booking data in spreadsheet looks like table in below, and each booking is for a full week. | wk1 | wk2 | wk3 | wk4 | wk5 |..........| wk52 | ================================== E1 | resv | |resv | |resv | |resv E2 | | resv |resv |resv | E3 | resv | resv |............................................... E4 | resv | E5 | ... | resv | resv|.................................... ... | E50|resv | resv | | resv It looks great excel but required one person to manage all bookings. So we moved to web interface and allow users to make their own bookings. Now, data moved to sql database with fields (id, wk#, room, other....), and records like below. 01 wk1 E1 02 wk1 E3 03 wk1 E4 ..... etc.... nn wk2 E2 nn wk2 E3 ... and more Now, I need a method in PHP to print above data in HTML table that looks like excel table in above. It doesn't have to print 52 wks in one page, but at least something like 4 wks view and next page to show the next 4 wks. At start it will print the first 4 wks from the current week (wk 11), and next page will print wk12 to wk15, etc. | wk1 | wk2 | wk3 | wk4 =================== E1 | resv | |resv | E2 | | resv |resv |resv E3 | resv | resv |............... E4 | resv | E5 | more rows...... Can someone here give me a direction how to code this in PHP? Thank you very much! bobo I would like to automaclly get posts in a thread manually. Here's my design: -Bot goes to topic, looking for posts -He would search for a <a name="POSTIDHERE">, idenfity it and start the logging loop -Firstly he searches for a field <span id="author"> and logs the content inside it -Then he searches for a field <span id="content"> and logs the content of it -Finally flush it into database (or do it when a step is completed) -When all posts on the page are dealt, move to the next page I don't have a problem with looping ATM, the place I am confused is the second step and the logging steps. How would I do them? In JavaScript there is something called getElementsById. I cannot find the same function in PHP. Thanks! Do anyone know how i can put the html tags in the same line as the other html tags? Here's an example: Code: [Select] Images | Link | Delete | Enabled On my code, it break the tags to the new line without put on the same line as the other tags. Here's the code: Code: [Select] [code]<?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypass'); define('DB_DATABASE', 'mydbtable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); if($username == '') { $errmsg_arr[] = 'username ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $qrytable1="SELECT images, id, public FROM members WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo '<p id="images"> <a href="images.php?id='.$row['id'].'">Images</a></td> | <a href="http://' . $row["links"] . '">Link</a> </td> | <a href="delete.php?id='.$row['id'].'">Delete</a> </td> | <p> <p id="test">'.$row['Public'].'</td>''; } } } ?>[/code] Hi, How do I open all HTML file contained in a folder, then search for the title of the page, and save the title in the database? Also, is it possible to do this using functions? Cheers. Hi
I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems.
1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that?
for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; }I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } }If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. Hi there. I'm doing a calendar page with php. It's based on a template and in this template all the output text and html-tags are saved into a xml string. I want to add a tooltip/hovering effect and found one on the net. I applied this script but it doesn't work. It works on "plain html", but when it is within the php it just won't work.. This is how my code looks like: START: $xml = '<?xml version="1.0" ?><response><content><![CDATA['; --- kode -- kode -- kode --- $xml.="<div class='calevent'> <a href='' class='someClass' title='<img src=1.jpg>'>Curabitur dolor eros</a> <a href='java script:navigate(\"\",\"\",\"".$row[0]."\")'>"; $xml.=$erow[0]; $xml.="</a></div>"; END: echo $xml; ------------- The script is supposed to add tooltips when an element is declared "someClass" and it works on plain html on the same page.. Take a look: http://clubbinghagen.dk/calendar/ Links in the calendar have no tooltip, but the Admin link in the center bottom (a bit hard to see!) has a working image as a tooltip. Any ideas?? Hello firstly i would like to say im very new to this forum (Signed up 5 minutes ago). I have decided to join as im in my final year at university and have been asked to create a website, so im guessing ill be coming back here a lot for help! . Anyway my most current problem is i have an if statement that hides the "Register" button if the user is logged in and Shows a welcome message and the users name if the user is logged in. However i would like to make the log in form disappear if the user is logged in. I know that by putting the form code in the else part of my if statement it will disappear if the user is logged in however when i do this it stops my whole website working. Any help would be very grateful. Thanks Glen. Hello, I just wanted to run over some code i'm using to loop through for a page. And wanted people critique on it really. It is a bit messy i feel trying to include all the html tags inside the loop in order for me to achieve the page look i want and whilst maintaining to xhtml standards. Would any one please take a look at my code which works and tell me how they would do it or if its done badly as i'm interested to know $q = "SELECT title, content, get, link FROM content WHERE page='index'"; $r = mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<h2>'; // print for start of H-tag echo $row['title']; // print title inside H-tag echo '</h2><p>'; // close H-tag, line break, start of P-tag $get = $row['get']; $link = $row['link']; $content = $row['content']; $content = explode(' ', $content); $y = 90; $x = 0; while ($x < $y) { echo $content[$x].' '; // print content inside P-tag $x++; } // end of content echo '</p><a href="seo.php?x='; // close P-tag, start A-Tag print link echo "$get"; // $_GET[''] echo '">read more...&#187;&#187;</a>'; // close url start the anchor text and close off </a> } // End of while echo '</div>'; // End of left content echo '<div class="right">'; // Start of right div echo '<h2>News</h2>'; // News title I'd appreciate any feed back from more experienced users/coders Thank you in advance :-) Hello, I'm working on a page where users can add articles by writing text in textareas with a WYSIWYG editor. When they submit the form it's saved in a database. As a summary of the article i grab the first 800 characters of the article, but as you could imagine there might occur html tags like <div> or <span> in the summary which are not closed. To prevent this from ruining my page layout when their articles are posted on the wegbsite I could use strip_tags but I'd like to keep the format, also this would delete images. I couldn't think of another solution then a function which checks for open tags and if so; add closing tags at the end of the summary. I already made a similar function a while back, but that one only checks for <div> and <span>, as those are the worst.. The nasty part is that I kind of deleted that function accidentally, and I can't fully remember how I wrote that.. So what I would like to have is a function that checks for all unclosed html tags and add the associated closing tags, in the right order, at the end of the summary. Any help getting on the right track is appreciated. I'm trying to learn php, and I've picked up a php/mysql member system type script, and I'm trying to put the login/sign-up forms into my own pages. The problem I'm having though is getting PHP and HTML to work in the same echo""; How can I add html tags in php as a variable? For example, for some reason my code gives me a header error if I use html before the php tags. I just need to add the style in there. I was wondering how I could add a style of any html tag within php as a variable?? Like I was thinking like <?php $style = "<style> div.error { border: 1px dashed #660000; background: #fee; color: #660000; } </style>"; echo $style; ?> But that would probably just print out the code... how can I make it so it wont print out on screen and I can actually use the style? Sorry for the noob question... im kind of an intermeddiate php programmer but the noobs questions still seem to never go away! Hi there i was wondering how i would go about using html tags inside the php tags so i could put data from a database into a textarea / text input i had a go but had no such luck with this attempt: <?php echo "Title:<br>"; echo "<input type="text" name="title" value="$row['Title']">"; ?> the code above is to give you an idea of what i want to do, if you can point me to any guides or show me how it will be greatly appriciated Thanks, Blink359 In my mail function, the $message parameter contains html tags such as <br><B> <a> etc etc.. But when I receive the email those tags are non functional. I do not get a bold text or a line break or a hyperlink as I should. How do i make it work? Hi, this is probably really simple for the majority here, but it's catching me out. I want to know what I need to add to the code below to strip <> HTML tags from the field post_title. Hope somebody can help. Thanks in advance. Code: [Select] <?php mysql_connect("********", "********", "********") or die(mysql_error()); mysql_select_db("website_news") or die(mysql_error()); $data = mysql_query("SELECT * FROM news_posts ORDER BY post_date DESC LIMIT 0, 5") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { Print "<font color='black' face='arial'><li><a href='/website/news/?p=".$info['ID'] . "'>"; if ( strlen($info['post_title']) > 60) { $PostTitle = substr($info['post_title'], 0, 60); print $PostTitle. "..."; } else { print $info['post_title']; } Print "</a> <font color=#666666><i> - posted on "; $date = date('j M \'y', strtotime($info['post_date'])); Print $date; Print "</i>"; } ?> |