Jump to content

dadamssg87

Members
  • Posts

    218
  • Joined

  • Last visited

Everything posted by dadamssg87

  1. I've been pulling my hair out over this. I have a web page that i'm trying to get the contents of all of the divs with a certain class. I figured xpath would be the best way to go but i can't figure it out and theres a surprising lack of examples/tutorials about using it with HTML. i have the following and i know i'm getting the right number of divs. I just don't know how to get their innerHTML/contents. $url = "http://www.vanityfair.com/politics/2012/10/michael-lewis-profile-barack-obama"; $ctx = stream_context_create(array('http'=> array('timeout' => 10))); libxml_use_internal_errors(TRUE); $num = 0; if($html = @file_get_contents($url,false,$ctx)){ $doc = DOMDocument::loadHTML($html); $xpath = new DOMXPath($doc); foreach($xpath->query('//div[@class="page-display"]') as $div){ $num++; echo "$num. "; // echo $div->item(0)->textContent; //???? echo "<br/>"; } echo "<br/>FINISHED"; } The $div->item(0)->textContent line breaks the loop and doesn't output anything.
  2. I'm trying to create a page that has several full blog posts. Each post will be echo'ed out within a loop. I want each blog title to have an anchor next to it. Something like "<a name="post_<?=$post_id;?>" /> under each blog title i want a link that links to the next blog title "<a href="#post_<?=$next_post_id;?>">Not interested? Skip to next article.</a>
  3. pretty much exactly what i'm doing with my echo statement. I just want to get the key of the next item in the array while in the loop.
  4. If i'm looping through an array how do i get the next item key. For example: $items['a'] = "One"; $items['b'] = "Two"; $items['c'] = "Three"; $items['d'] = "Four"; foreach($items as $key => $value){ $next_item = next($items); $next_key = key($next_item); echo "The current value is $value. The next key is $next_key.<br/>"; } $next_item is returned as a string. The key() function is failing.
  5. Let's say i have a timestamp stored in my database. I also have a form that user's can input a time and a timezone offset(-5, -4, -3, etc.). How would i check if the user inputted a time that is greater than the timestamp?
  6. Thanks for the responses! buuuut it's still not doing what i need to be doing. The provided $str being a url is just an example string because it contains characters i'm wanting to strip. I won't strictly be using this on urls. $str = 'http://feeds.feedburner.com/techcrunch/startups?format=xml'; echo preg_replace("[^\w?',!\"-]", "", $str );
  7. I think i'm missing something. The following string is exactly the same after it goes through str_replace...? $str = 'http://feeds.feedburner.com/techcrunch/startups?format=xml'; echo str_replace("[^\w?',!\"-]", "", $str );
  8. sweeeet. What if i wanted to add commas and exclamation points?
  9. i'm trying to figure out how to write a function that strips anything other than: 1. alpha-numeric characters 2. underscore _ 3. hyphen - 4. question mark ? 5. apostrophe ' 6. quotation mark " I've got the alphanumeric part down, i just don't know how to add those other characters str_replace("[^A-Za-z0-9]", "", $string_to_be_stripped );
  10. I've never implemented a try catch statement. I'm having trouble figuring out what exactly will get caught. I have the following code but i'm still getting php errors because the simplexml_load_string() is trying to parse a string that's not xml. I thought a try catch would work here. What am i doing wrong? function _check_xml($str) { try { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $str); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); if(simplexml_load_string($output)) { return TRUE; } else { $this->form_validation->set_message('_check_xml', 'The simplexml_load_string() function did not receive xml.'); return FALSE; } } catch(Exception $e) { $this->form_validation->set_message('_check_xml', 'The url could not be reached.'); return FALSE; } }
  11. was no change with the displaying of the errors. Still getting php errors that i'm getting an undefined index with $_FILES(the name of the form input). phpinfo() shows 8M for both moster and local. register_globals is off.
  12. That response was with my edited target patch.
  13. @PFMaBiSmAd, no "B" with it, just "8M". $_SERVER['content_length'] shows 494079. @QuickOldCar, i get "Select your file to upload." with your script.
  14. that script wouldn't work if there are no $_POST or $_FILES variables
  15. I'm trying to do a simple image upload. It works fine on my local server but i'm moving all my files to my production server and some files i attempt to upload, via an html form, don't register. The $_FILES variable doesn't exist sometimes. I think its because of the file size but i'm not sure. The form has two inputs: "title" and "userfile". I can put something in the title and attempt to upload a small excel file and both $_POST and $_FILES exist but if i do a larger image file both $_POST and $_FILES don't even get set. I did an "echo ini_get('post_max_size');" and i get "8M". The image i'm attempting to upload is only 0.34M so i should be good there. I've replaced the actual upload script with this, which is how i found out the variables only get set sometimes Any suggestions would be much appreciated. <?php echo "Upload: " . $_FILES["userfile"]["name"] . "<br />"; echo "Type: " . $_FILES["userfile"]["type"] . "<br />"; echo "Size: " . ($_FILES["userfile"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["userfile"]["tmp_name"]; echo "<hr><pre>"; print_r($_POST); echo "</pre><hr>"; echo "<pre>"; print_r($_FILES); echo "</pre>";
  16. i don't think i'm being clear enough. My users create accounts in my app. They all have their own password. I have a hardcoded admin password in my code. So if i, or anyone else, inputs the admin password for user's account i/they will gain access. This way i don't have to know all of my user's passwords. Since hardcoding passwords is generally a bad idea, i'm trying to figure out a good way to do this.
  17. well you shouldn't be storing ANY billing information in your database at all. ever. There are PCI-compliant(credit card compliance standards) payment gateways that can do this for you(authorize.net's CIM) if you really need it. The typical workflow will be: user adds item to cart, user enters in billing info, your app validates the data and then passes this data to a payment gateway(authorize.net), the payment gateway will send back a response(XML), your app reads the response, redisplays the payment form if unsuccessful, sends them to a thank you page if successful. Obviously you'll need an SSL certificate and something other than shared hosting. Private server or virtual private server.
  18. Can someone suggest a way i can incorporate an admin password to access all accounts of my app? I'm hardcoding it right now but i know thats a bad idea. Should i create a db table just for this? hardcode it another file and then include that file?
  19. I'm developing a an ecommerce solution for a narrow market. My clients will all have their own existing websites. Their store will be built and hosted on my website. To connect their existing website with their storefront i'd like them to copy/paste an html snippet on their website. Very similar to how you can post some snippet to have a facebook "like" button on your webpage. The tricky part is that i want to create a lot of "Purchase" buttons with different shapes and sizes so they can test what works best for them. I want them to be able to change how their "Purchase Now" button looks from my website and the changes would get reflected to their website. I only want them to have to copy/paste the code snippet once though. So i was thinking i could write a script that based on their chosen button style would output a .png image so they would copy/paste something like this once: The script would look up username 1234's button preference and then spit out a .png image. Doing it this way, rather than an iframe, wouldn't limit me to a certain height and width. Thoughts? It seems like everybody else uses iframes but my button only contains an image and isn't a widget. Think doing it this was is best?
  20. Table structure id(int)date(date)group(int)deleted(timestamp)rate(decimal(6,2)) 12011-12-1420000-00-00 00:00:0099.99 22012-01-1920000-00-00 00:00:00149.99 32012-07-2830000-00-00 00:00:00249.99 42012-03-0350000-00-00 00:00:0049.99 I'm receiving an array of group id's and dates. I'm imploding them and separating them by commas to form strings. I'm trying to write a query that only pulls up rows that have groups that are in the group string and dates that in the dates string. <?php $groups[] = 2; $groups[] = 5; $dates[] = "2011-12-14"; $dates[] = "2011-12-15"; $dates[] = "2011-12-16"; $dates[] = "2012-03-03"; $groups = implode(',', $groups); $dates = implode(',',$dates); $query = "SELECT * FROM `Exceptions` where `group` in($groups) AND `date` in($dates) AND deleted = '0000-00-00 00:00:00'"; ?> This query results in zero rows. I'm expecting to get get row 1 and row 4. Anybody know what i'm doing wrong?
  21. Is there a way to tell the loop you are iterating through to move onto the next item if a certain condition is met without having a bunch of nested if statements? <?php foreach($item as $key => $value) { //code to manipulate the data if($data == $condition1){ //move on to next item} //manipulate data more if($data == $condition2){ //move on to next item} //manipulate data even more if($data == $condition3){ //move on to next item} //you get the idea }
  22. * SELECT id, username, code, price, iteration FROM Products where iteration = ( SELECT MAX(iteration) FROM Products WHERE username = '4' )
×
×
  • 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.