Jump to content

dadamssg87

Members
  • Posts

    218
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

dadamssg87's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  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
×
×
  • 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.