Jump to content

whatnow

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by whatnow

  1. ah so good of you, thank you very much - works perfectly. I REALLY need to go learn regex, I have a feeling it'd make a lot of my code more efficient!! thanks again
  2. OK, this has to be so simple but i'm sitting in a could of confusion over this and going a little phpotty The string is a local directory, let's say: $y = www/repository/FT/forward/slashes/FT_-_forwardslashes2 but I'm building a string checking routine to ensure it can't be: $y = www/ims_repository/FT////forward//////slashes//FT_-_forwardslashes2 for example. Now what I'm thinking is something like: $x = explode('/', $y); foreach ($x as $key => $value){ $tmpStr .= $value . '/'; if ($tmpStr = ????) { $tmpStr="" } } or maybe $x = explode('/', $y); foreach ($x as $key => $value){ $tmpStr .= $value . '/'; $z = strlen($tmpStr) for ($i=0; $i<=$z; $i++) { ????// check if multiple slashes and reduce to one. } } the ???? bit is what's getting me, if this routine is even close, this part is what I need to check for more than one slash and swap it for just one. I have a feeling there's a really obvious regex to help me out? I'd really appreciate any help.
  3. never mind, I've found a dirty hack which will do the job. something like this; <?php $config['url'] = "http://www.pharmatimes.com/WorldNews/article.aspx?id=12190"; // url of html to grab $config['start_tag'] = "<body>"; // where you want to start grabbing $config['end_tag'] = "</body>"; // where you want to stop grabbing $config['show_tags'] = 1; // do you want the tags to be shown when you show the html? 1 = yes, 0 = no class grabber { var $error = ''; var $html = ''; function grabhtml( $url, $start, $end ) { $file = file_get_contents( $url ); if( $file ) { if( preg_match_all( "#$start(.*?)$end#s", $file, $match ) ) { $this->html = $match; } else { $this->error = "Tags cannot be found."; } } else { $this->error = "Site cannot be found!"; } } function strip( $html, $show, $start, $end ) { if( !$show ) { $html = str_replace( $start, "", $html ); $html = str_replace( $end, "", $html ); return $html; } else { return $html; } } } $grab = new grabber; $grab->grabhtml( $config['url'], $config['start_tag'], $config['end_tag'] ); echo $grab->error; foreach( $grab->html[0] as $html ) { $string1 = stristr( $grab->strip( $html, $config['show_tags'], $config['start_tag'], $config['end_tag'] ),'<span class="body">' ) . "<br>"; } $string2 = (explode('span',$string1)); $string2 = $string2[1]; echo $string2; ?> but it's not very clean, but it works, so horray for me.
  4. I have the following code which grabs a RSS feed, it shows up the results in my browser as: Now how would I go about actually making it read the RSS, take on board the URL for the full article and then additionally grabbing the artical from the webpage, as to result in: The page itself has the content in a span class; named 'newsContent'. Do I just need to make a code which just lifts this span out of the page? That seems like a inefficient method of what I want to achieve, when ideally I could just call the content in another way? Are there other ways, or is a crude method the onyl way to take content from other sites like this? ( I will happily admit, I am fresh to RSS ) I've been searching the internet for this for three hours now and to be honest i'm not getting good results. I've read about bloggers stealing content so it seems possible but i've not found any practical code for doing just that. I assure you this isn't for illicit gains, I've been asked to do it for a job interview i'm preparing for, so naturally any help would be more than appreciated. Code: <?php $rssFeeds = array ('http://www.pharmatimes.com/p.aspx?n=ZGFpbHl2aWRlb25ld3M=&s=VmlkZW9OZXdz'); //Loop through the array, reading the feeds one by one foreach ($rssFeeds as $feed) { readFeeds($feed); } function startElement($xp,$name,$attributes) { global $item,$currentElement; $currentElement = $name; //the other functions will always know which element we're parsing if ($currentElement == 'ITEM') { //by default PHP converts everything to uppercase $item = true; // We're only interested in the contents of the item element. This flag keeps track of where we are }} function endElement($xp,$name) { global $item,$currentElement,$title,$description,$link; if ($name == 'ITEM') { // If we're at the end of the item element, display // the data, and reset the globals echo "<b>Title:</b> $title<br>"; echo "<b>Description:</b> $description<br>"; echo "<b>Link:</b> $link<br><br>"; $title = ''; $description = ''; $link = ''; $item = false; }} function characterDataHandler($xp,$data) { global $item,$currentElement,$title,$description,$link; if ($item) { //Only add to the globals if we're inside an item element. switch($currentElement) { case "TITLE": $title .= $data; // We use .= because this function may be called multiple times for one element. break; case "DESCRIPTION": $description.=$data; break; case "LINK": $link.=$data; break; }} }} function readFeeds($feed) { $fh = fopen($feed,'r'); // open file for reading $xp = xml_parser_create(); // Create an XML parser resource xml_set_element_handler($xp, "startElement", "endElement"); // defines which functions to call when element started/ended xml_set_character_data_handler($xp, "characterDataHandler"); while ($data = fread($fh, 4096)) { if (!xml_parse($xp,$data)) { return 'Error in the feed'; } } } ?>
  5. what i'm trying to do is simple but I can't get passed it. essentially i've got a form with a variable 'searchQry' this is what the user types into and processes when the form is clicked to the PHP file. I then want the php file to take searchQry and send it to multiple search engines, all of which have different variable names to perform a search, e.g. Google's is 'q', however another might be 'qry' or anything really. what i'm aiming for is a site which operates very much like a torrent multiple search engine device. The ones where you enter one string and then it'll search all the sites for you with that string. Any ideas? I could write the pseudo-code if it makes it easier? tia clever people.
  6. [!--quoteo(post=351159:date=Mar 2 2006, 11:29 PM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Mar 2 2006, 11:29 PM) [snapback]351159[/snapback][/div][div class=\'quotemain\'][!--quotec--] hmmm... well, I can see that you forgot a ";" at the end of $link, that's about all I see though [/quote] thanks mate ;) all working like a dream now ! I really appreciate your input, this puts me well ahead of myself now. mystery solved
  7. Thanks for the speedy response. Your code looks a lot better, thank you. The problem is I still can't get it to work :( here's what i've got: [code] <?php //start a session to remember variables session_start(); include "config.php"; include "header.inc"; $cookie_info = explode("-", $_COOKIE['mysite_username']); $usernameCookie = $cookie_info[0]; $link = mysql_connect($server, $db_user, $db_pass) $db_select = mysql_select_db($database, $link); $query = "SELECT image FROM $table WHERE username = '$usernameCookie'"; $result = mysql_query($query, $link)      or die("Couldn't select result".mysql_error() ); echo mysql_result($result, 0); include 'footer.inc'; ?>[/code] that's the page in it's entirity. On viewing I get a white page :(
  8. I do intend to minimse on posting stupid threads but please allow me this one...feckin noob that I am. ALL i wanted to do was get a single result from my database. I've searched many online books my uni provide and i've trawled the net but I never got a proper explination of how to use mysql_db_query that I had to ask here. I know how to call it, I just can't get my query right, take a look: [code] $cookie_info = explode("-", $_COOKIE['mysite_username']); $usernameCookie = $cookie_info[0]; mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); $result = mysql_db_query($database, "SELECT image FROM $table WHERE username = '$usernameCookie'") or die (mysql_error()); echo "username: $usernameCookie result: $result image: $image"; if (mysql_num_rows($result)) {    echo "list of users:<ul>";    while ($qry = mysql_fetch_array($result)) {       echo "<li>$qry[username]</li>";    }    echo "</ul>end list of users."; }[/code] I chose the query becuase I have a table which is $table from my config file, this is read fine. The structure of the table is: username password image I can echo $username so it's read correctly from the cookie but I can't select the user's 'image' variable (URL of a image) from the DB. this is what's outputted from the code: [!--html--][div class=\'htmltop\']HTML[/div][div class=\'htmlmain\'][!--html1--]username: qwerty result: Resource id #5 image: list of users: end list of users.[!--html2--][/div][!--html3--] It's mystified me, after a day learning php this is the thing that i've spent most time on and got nowhere with. After the 3rd hour I had to post on here as I was going around in circles ! tia.
  9. thanks, yes i'm now doing that a lot just to check code in chunks...better to have visual errors :)
  10. got it, made sense that I needed to add this: $username = $_POST['username']; but i'm not sure if i'm there yet, hehe, however I can now print the posted details :)
  11. Hi, thanks for your reply, it makes sense what you mention and i've changed it. The only problem is that i still can't get the variable $username out. If I log in with a incorrect password it'll stop the user and say 'Sorry, there is no username with the specified password.' however my code is: [code]echo "Sorry, there is no username $username with the specified password.<br>"; [/code] It wont pump out $username under any echo or print. This in turn stops the cookie from being set as the value $username must be null...i've checked my I.E. cookies and it still wont make it. I have no idea why though, it was working at one point and then I bodged it up :(
  12. hi, I hope this isn't too noobish for even the noob's forum but i've only been on PHP for one day and a half, so please be gentle. This is my login.php code. A simple form on login.html sends the data, i've checked with the Db and it inputs the data fine. It's reading the variables back out of the db that seems to be the issue. I've checked my cookie folder (testing on IE for now) and it'll create the cookie for loggedin but not mysite_username :( this is my code processing the login, [code]<?php ob_start(); include("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); //select the username and password for a positive Ident. $match = "select id from $table where username = '".$_POST['username']."' and password = '".$_POST['password']."';"; //query the match $qry = mysql_query($match) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); //if there's none, tell the user to try again. if ($num_rows <= 0) { echo "Sorry, there is no username $username with the specified password.<br>"; echo "<a href=login.html>Try again</a>"; exit; } else { //set two cookies, one to say the user is logged in. setcookie("loggedin", "TRUE", time()+(3600 * 24)); //the second (not working) to set the username value to a cookie for later comsumption. setcookie("mysite_username", "$username"); //retrieve the info previously saved...not working either. $cookie_info = explode("-", $_COOKIE['mysite_username']); $username = $cookie_info[0]; echo "hi: $username<br><br>"; echo "You are now logged in!<br>"; echo "Continue to the <a href=members.php>members</a> section."; } ob_end_flush(); ?>[/code] thanks in advance,
×
×
  • 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.