PHP - Cli - Automaclly Getting Stuff In Html, Split By Class Ids
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! Similar TutorialsOkay the page is structed like this. lets says i have a http://site.com/sdsddsa And it shows the following Quote <div class="data"> <div class="title"> <a class="title" href="http://www.site.com/product/dp/ITEMID/ref=sr_1_1?s=automotive&ie=UTF8&qid=1291906958&sr=1-1">ITEM ID</a> </div> <div class="newPrice"> <a href="http://www.site.com/product/dp/ITEMID/ref=sr_1_1?s=automotive&ie=UTF8&qid=1291906958&sr=1-1" > Buy new</a>:<span class="price"> $12.95</span> </div><br class="unfloat"> <div class="usedNewPrice"> <span class="subPrice"> <a href="http://www.site.com/product/dp/ITEMID/ref=sr_1_1?s=automotive&ie=UTF8&qid=1291906958&sr=1-1">2 new</a> from <span class="price">$12.95</span></span> <br class="unfloat"> </div> <div class="fastTrack"> <span class="getItBy">Get it by <span class='deliveryDate'>Friday, Dec 10</span></span> if you order in the next <span class='timeLeft'>8 hours</span> and choose one-day shipping.</div> <div class="sss"> Eligible for <span class="sssFree">FREE</span><span class="sssLastLine"> Super Saver Shipping.</span> </div> <div class="lowStock"> Only 3 left in stock - order soon.</div> </div> </div> And it repeated again! I need the ITEMID number from the LISTING and the Price for the item ID number. Can anyone help please! 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. How do i turn this: public function show_errors() { foreach($this->errors as $key=>$value) echo $value; } ..into something that sends the $value to a class or a specific element in my HTML document? Hello I want to be able to change the class depending on if a variable is 1 or 0. <html> <p class="note-general"> This is the general </p> <p class="note-warning"> And this is the warning </p> </html> I want the variable $adult (that can be 1 or 0) to set if the class should be a note-general or note-warning. Thank you for support hello guys, i'm new here, looking for some help.. here is the situation: This script is working fine on PHP 5.3.1 but i got a new host that uses 5.3.6 and now its no longer working? What can i change to make it work, and does anyone know where i can learn the different coding between the 2 updates? Code: [Select] <? include 'cpheader.php'; if (isset($_POST['submit'])) { $error = ($_POST['title'] == "") ? "You need to have a title!" : $error; $error = ($_POST['message'] == "") ? "You need to have a message!" : $error; if($error == ""){ $time = time(); $result= mysql_query("INSERT INTO `ads` VALUES('".$time."', '$user_class->id', '".$_POST['title']."', '".$_POST['message']."')"); echo Message("You have posted a news update.); } else { echo Message($error); } } ?> <tr><td class="contenthead">Post News</td></tr> <tr><td class="contentcontent"> This is the news that posts on the main page after you log in. HTML is turned on and you may use it to make your posts look a bit better than normal text, as well as add images. </td></tr> <tr><td class="contentcontent"> <form method='post'> <table width='100%'> <tr> <td width='25%'>Title:</td> <td width='25%'> <input type='text' name='title' size='40' maxlength='100'> </td> </tr> <tr> <td width='25%'>Message:</td> <td width='25%'> <textarea name='message' cols='60' rows='4' ></textarea> </td> </tr> <tr> <td width='25%'>Submit:</td> <td width='25%'> <input type='submit' name='submit' value='Post'> </td> </tr> </table> </form> </td></tr> <? include 'footer.php'; ?> Why is it when a save a youtube video on my db it gives me this <iframe width="220" height="240" src="http://www.youtube.com/embed/DCZ2l1BbWyY?wmode=opaque" frameborder="0" allowfullscreen></iframe><br> i have to save it twice so it can be view why if you want to see my edit videos page i will add it here I have a string: "system_controllers_qty" and i need it to be: "system_controllers.system_controllers_qty" I can use substr because the It wont always be 'system_controllers', it can be 'system_cpus' for example so I need to somehow break and the second underscore if possible. Any ideas? I got a snippet of code from here that will give me the Monday of any submitted date, so if I pass 12/08/10 it'll return 12/06/10 as the Monday, which is correct. I tried to expand it to give me the Tuesday of that week: Code: [Select] function getWeekDays($date) { $offset = ''; if( date('l', strtotime($date)) == 'Monday' ) { $offset = ''; } elseif( date('l', strtotime($date)) == 'Sunday' ) { $offset = 'Tomorrow'; } else { $offset = 'Last Monday'; } $monday = date('m/d/Y', strtotime("$date $offset")); $tuesday = date('m/d/Y', strtotime("+1 day", $monday)); return $tuesday; } I keep getting the UNIX epoch returned for $tuesday...obviously this is just confusing the crap out of me, could someone explain what it is I am doing wrong? Thanks This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=318433.0 I've been trying for days to get this simple 1990's code to work. It won't work. Now, I don't even want to get it to work, because it's crappy ugly 1990's code... Is there an elegant way to accomplish this? (I just want to be able to manually override the default catalog prices as needed.) <?php //default catalog prices: $sku = "123456"; $price = "5.99"; if(isset($_POST[$sku])) { // if form submitted, and if( ${$_POST[$sku]} != $price) { //...and I manually changed price $price = ${$_POST[$sku]}; //...then change price to what I input } } echo '<form name="form1" method="post" action="Crappy1990sCodePage.php">'; echo '<input type="text" name="'.$sku.'" value="'.$price.'">'; echo '<input type="text" name="'.$sku.'" value="'.$price.'">';// (same sku may be listed twice) echo '<input type="submit" class="no_class_its_the_90s_remember">' echo '</form>'; ?> Thank you 😀 Edited July 25, 2020 by StevenOliverinclude "header.php"; if(isset($_GET['post_id'])) { $select=mysqli_query($con,"select...."); while($data=mysqli_fetch_array($select)) { echo "bla bla bla"; to_head("<title>asd</title><meta itemprop="name" content="asdfasdf">..."); } } include "footer.php";This is samthing what i want... I have header.php and footer.php and any script ex news.php where how news and read SEO stuff from database and put in HEAD of the document. I tried with jquery like $("head").append(str); and it works but then i read google don't run jquery when vist website. This is done with drupal, wordpress and php-fusion Drupal: https://api.drupal.o...add_html_head/7 php-fusion: https://www.php-fusi...thread_id=30959 so it is possible but i don't know how. Any idea? This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=354568.0 i can do stuff in html, php, flash, java and server developement
and work for more then 8 years in different segments for webprogramming.
german.
OK, about ready to go postal, as I've been wasting inordinate amounts of time trying to resolve this issue! If I create basic HTML echo-ed content, PHP works fine. But if I try to reference any database related syntax, the whole PHP web page breaks! VERY FRUSTRATING. This works: <?php // Printing results in HTML echo "<html>\n"; echo "<head>"; echo "</head>"; echo "<body bgcolor=\"#CCCCCC\">"; echo "<CENTER><H1>Current Inventory</H1>"; but this blows up and just gives me a white page with nothing!: <?php // Printing results in HTML echo "<html>\n"; echo "<head>"; echo "</head>"; echo "<body bgcolor=\"#CCCCCC\">"; echo "<CENTER><H1>Current Inventory</H1>"; $dbhostip = "192.168.0.10"; $dbport = "5432"; $dbname = "testdata"; $dbuser = "postgres"; $dbpass = "password1"; $dbconn = pg_connect($dbhostip,$dbport,$dbname,$dbuser,$dbpass); echo $dbconn; if(!$dbconn) { echo "An error has occurred (line 17)\n"; exit; } $result = pg_query($dbconn, "SELECT * FROM inventory"); if(!$result){ echo "An error has occurred (line 24)\n"; exit; } $resultCheck = pg_num_rows($result); if ($resultCheck > 0) { while ($row = pg_fetch_assoc($result)){ echo $row['cid']; echo $row['item_title']; } } ?> Any help would be appreciated. It seems that anything with $whatever causes the issue...  Hi I would like to know how to make a link select certain stuff from the database. For example the link called cape town with the id 11 is selected then the link must search through the events table for the city_id 11 and take that information and display it in another page. I would like to know how to do that or can you let me know of place that I can look. I have tried google but I don't know how to put what I'm looking for in words Hi, I'm designing a website for an online radio station. One show a week they have a DJ who has his own top 40 show with HIS top 40 listed on his own site At the moment, the only solution I have to getting the top 40 onto my clients site is an iframe (not good I know!) However, what's worse is that this top 40 list has horrendous colours that completely break the theme of my clients site and worse still, is Excel generated HTML! The author of this list is not a client of mine, and so, I can't do anything to persuade him to change. I've attached a copy of the offending file so you can see what I'm working with, changed the extension from html to txt for the forum post. Just for clarification, the excel generated HTML file is not hosted on my server (although I could set up a cron job to get it if required) I've done some digging and found a useful bit of code However, it displays the table 4 or 5 times In addition to this, is there a way to manipulate the width of the columns with this code? Code: [Select] <?php $oldSetting = libxml_use_internal_errors( true ); libxml_clear_errors(); $html = new DOMDocument(); $html->loadHtmlFile('Chart%20Table2.htm'); $xpath = new DOMXPath( $html ); $elements = $xpath->query( "//table" ); foreach ( $elements as $item ) { $newDom = new DOMDocument; $newDom->appendChild($newDom->importNode($item,true)); $xpath = new DOMXPath( $newDom ); foreach ($item->attributes as $attribute) { for ($node = $item->firstChild; $node !== NULL; $node = $node->nextSibling) { if (($attribute->nodeName =='valign') && ($attribute->nodeValue=='top')) { print($node->nodeValue); } else { print("<br>".$node->nodeValue); } } print("<br>"); } } libxml_clear_errors(); libxml_use_internal_errors( $oldSetting ); ?> Basically, I just want the table, I'm not bothered about the first column that contains some pictures as I think that's a separate table Ideally, I'd like to apply my own formatting to the table too (padding etc) if that is possible (eg from line 897 <td class=xl28 x:num>1</td>) down to line 1433 The trouble is, there is a lot of custom widths and styles inbetween which I don't want I'd like all the tr and td's without all the associated guff from the original export from Excel Geez I wish there was an easy way to get this guy just to export as CSV but unfortunately that's not an option! Many thanks in advance! Hi, I wrote a classFile to handle files that looks like this: class classfile { //path_parths is an array, use it this way //path_parts["filename"] -> filename //path_parts["dirname"] -> directory //path_parts["extension"] //path_parts["basename"] protected $path_parts; private $fullpath; function __construct($filename){ if(file_exists($filename)){ $this->fullpath = $filename; $this->path_parts= pathinfo($this->fullpath); } else{ die("File or Folder doesn't exist"); } } function move($destination){ if (file_exists($destination)){ rename($this->fullpath, $destination . "/" . $this->getfilename()); //Update properties $this->setfullpath($destination . $this->getfilename()); $this->setpath_parts(); } else{ die("The folder specified doesn't exist"); } } function copy($destination){ copy($this->fullpath, $destination); } function getpath(){ return $this->path_parts["dirname"]; } function getfilename(){ return $this->path_parts["basename"]; } function getextension(){ return $this->path_parts["extension"]; } function getfullpath(){ return $this->fullpath; } function setfullpath($path){ $this->fullpath = $path; } function setpath_parts(){ $this->path_parts = pathinfo($this->fullpath); } function __destruct() { ; } } ?> Then I extended it with a class to handle images that looks like this: include 'c:/wamp/www/classfile.php'; class classimage extends classfile{ var $image; var $image_info; var $image_type; function __construct($filename){ parent::__construct($filename); $this->image_info = getimagesize(parent::getfullpath()); $this->image_type = $this->image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg(parent::getfullpath()); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif(parent::getfullpath()); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng(parent::getfullpath()); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=80, $permissions=777) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image); } } function getWidth() { return $this->image_info[0]; } function getHeight() { return $this->image_info[1]; } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function scale($scale) { $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); echo "resized to:\n"; echo $width . "\n"; echo $height . "\n"; echo "imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight())\n"; imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } function format(){ $width = $this->getWidth(); $height = $this->getHeight(); if ($width > $height){ return "landscape"; } if ($height > $width){ return "portrait"; } if ($height == $width){ return "square"; } } function isTooBig($maxsize){ $width = $this->getWidth(); $height = $this->getHeight(); if ($width > $maxsize || $height > $maxsize){ return true; } else{ return false; } } function __destruct() { ; } } ?> Now that I got this, I loop through images located in a folder that way: if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle))) { //Instantiate the object $image = new classimage($directory . "/" . $file); //And do quite a lot of verification and particularly this: if ($image->format() == "landscape") { echo "width: " . $image->getWidth() . "\n"; echo "height: " . $image->getHeight() . "\n"; if ($image->isTooBig($maxsize_mini)) { $image->resizeToWidth($maxsize_mini); $image->save($directory . "/mini_" . $image->getfilename()); } } } And now to the problem: I echo'ed the resize function to see what's being run and I got that: picture1 imagecopyresampled(Resource id #26, Resource id #25, 0, 0, 0, 0, 608, 405.65, (), ()) picture2 imagecopyresampled(Resource id #27, Resource id #26, 0, 0, 0, 0, 250, 166.796875, (), ()) It looks like it's reusing an instantiation of the previous object and so on and so forth. In my mind, the way it should look is: picture1 imagecopyresampled(Resource id #2, Resource id #1, 0, 0, 0, 0, 608, 405.65, (), ()) picture2 imagecopyresampled(Resource id #2, Resource id #1, 0, 0, 0, 0, 250, 166.796875, (), ()) The previous object is destructed, the new one has the old id. how does that work? The reason I ask and wonder about this is because I'm having weird result for the resize such as a ridiculously small picture mini size in the actual mini size picture (250 px) except whatever is left is filled with black. I have mysqli object in Database class base: [color=]database class:[/color] class Database { private $dbLink = null; public function __construct() { if (is_null($this->dbLink)) { // load db information to connect $init_array = parse_ini_file("../init.ini.inc", true); $this->dbLink = new mysqli($init_array['database']['host'], $init_array['database']['usr'], $init_array['database']['pwd'], $init_array['database']['db']); if (mysqli_connect_errno()) { $this->dbLink = null; } } } public function __destruct() { $this->dbLink->close(); } } Class derived is Articles where I use object dBLink in base (or parent) class and I can't access to mysqli methods (dbLink member of base class): Articles class: require_once ('./includes/db.inc'); class Articles extends Database{ private $id, .... .... $visible = null; public function __construct() { // Set date as 2009-07-08 07:35:00 $this->lastUpdDate = date('Y-m-d H:i:s'); $this->creationDate = date('Y-m-d H:i:s'); } // Setter .... .... // Getter .... .... public function getArticlesByPosition($numArticles) { if ($result = $this->dbLink->query('SELECT * FROM articles ORDER BY position LIMIT '.$numArticles)) { $i = 0; while ($ret = $result->fetch_array(MYSQLI_ASSOC)) { $arts[$i] = $ret; } $result->close(); return $arts; } } } In my front page php I use article class: include_once('./includes/articles.inc'); $articlesObj = new articles(); $articles = $articlesObj->getArticlesByPosition(1); var_dump($articles); [color=]Error that go out is follow[/color] Notice: Undefined property: Articles::$dbLink in articles.inc on line 89 Fatal error: Call to a member function query() on a non-object in articles.inc on line 89 If I remove constructor on derived class Articles result don't change Please help me Hi Can you call Class A's methods or properties from Class B's methods? Thanks. |