Jump to content

dadamssg

Members
  • Posts

    729
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dadamssg's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. they're user uploaded photos and will be contacting each user to ask for their permission to use the photos.
  2. I'm trying to scrape images from the mark-up of certain webpages. These webpages all have a slideshow. Their sources are contained in javascript objects on the page. I'm thinking i need to get_file_contents("http://www.example.com/page/1"); and then have a preg_match_all() function that i can input a phrase(ie. '"LargeUrl": ', or '"Description":') and get whatever's in the quotes directly after those instances. var photos = {}; photos['photo-391094'] = {"LargeUrl": "http://www.example.org/images/1.png","Description":"blah blah balh"}; photos['photo-391095'] = {"LargeUrl": "http://www.example.org/images/2.png","Description":"blah blah balh"}; photos['photo-391096'] = {"LargeUrl": "http://www.example.org/images/3.png","Description":"blah blah balh"}; I have this function, but it returns the entire line after the input phrase. How can i modify it to look for whatever's in quotes directly after the input keyword? Or am i doing it all wrong and theres an easier way? $page = file_get_contents("http://www.example.org/page/1"); $word = "\"LargeUrl\":"; if(preg_match_all("/(?<=$word)\S+/i", $page, $matches)) { echo "<pre>"; print_r($matches); echo "</pre>"; }
  3. awesome. thanks. Here's my function function get_phrase_after_string($haystack,$needle) { //length of needle $len = strlen($needle); //matches $needle until hits a \n or \r if(preg_match("#$needle([^\r\n]+)#i", $haystack, $match)) { //length of matched text $rsp = strlen($match[0]); //determine what to remove $back = $rsp - $len; return trim(substr($match[0],- $back)); } }
  4. thanks for the that, xyph. I did the following but it is returning "Property: " with it. Anyway to cut that out? $body = "Dear John Doe, your information is below Check in date: 07/23/2012 Check out date: 07/26/2012 Property: The best inn around \n Alternate Check in date: 07/27/2012 Alternate Check out date: 07/29/2012"; echo "$body<br/><br/>"; if(preg_match('/(?<=Check in date: )\S+/i', $body, $match)) { echo $match[0]."<br/><br/>"; //returns '07/23/2012' } if(preg_match('#Property: [^\r\n]+#i', $body, $match)) { echo $match[0]; //returns 'Property: The best inn around' }
  5. I have this function to search for a 'word'(string with white spaces around it) after a specified string and it works great. I need to modify it to where it looks for all characters after the specified string until it hits a new line. The following returns "07/23/2012". But i would like to do is modify it so if i input "Property: " into the preg_match function it returns "The best resort in town". I suck at regex though. Any help would be much appreciated. thanks! $body = "Dear John Doe, your information is below Property: The best resort in town Check in date: 07/23/2012 Check out date: 07/26/2012 Alternate Check in date: 07/27/2012 Alternate Check out date: 07/29/2012"; if(preg_match('/(?<=Check in date: )\S+/i', $body, $match)) { echo $match[0]; }
  6. so i've been developing in the CodeIgniter framework and i have yet to code an object. My app deals with bookings. So in the database i have columns like: start, end, created, created_by, title, description, etc. I pull the data out and put it into an array. I use my controller functions to validate data and model functions to delete/edit/create the bookings. Should i write a class that creates a Booking object? i don't see how that would benefit me though. How do you guys determine what needs to be an object?
  7. perfect. thanks!
  8. I found this preg_match() function which searches the parts of a string and uses the checkdate() function to see if it is a date. It expects the format of the date to be "YYYY-MM-DD". I would like to rewrite it to expect the format to be "MM/DD/YYYY". <?php function checkDateFormat($date) { //match the format of the date if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $date, $parts)) { //check weather the date is valid of not if(checkdate($parts[2],$parts[3],$parts[1])) return true; else return false; } else return false; } I'm pretty sure the following is write to change the string length of each part but i don't know how to change the expected "-"'s to be a "/"'s. <?php if (preg_match ("/^([0-9]{2})-([0-9]{2})-([0-9]{4})$/", $date, $parts)) Any help would be greatly appreciated!
  9. perfect @barand. exactly what i needed. thanks!
  10. Say i have two arrays with custom keys. What would be the easiest way to write a function that would determine if all the keys in arrayOne are in arrayTwo? The example below would return false because keys 3 and 4 are missing in arrayTwo. Any help would be much appreciate. thanks! <?php $arrayOne['1'] = "adg"; $arrayOne['2'] = "a4g"; $arrayOne['3'] = "346"; $arrayOne['4'] = "etwe"; $arrayTwo['1'] = "xcb"; $arrayTwo['2'] = "acbr"; $arrayTwo['6'] = "yiy"; $arrayTwo['7'] = "mmm"; ?>
  11. this is great. Thank you so much! I'm in Texas as well!
  12. I'm trying to figure out how i should be storing itemized order information. My orders require a down payment and has multiple taxes, each with their own rate. What should my database look like? I know i should be storing the base price. Then, should i store the tax rates for each order or tax amounts with each item in a row? Then for the transactions(deposit and remainder)...should i store the exact amount of the base prices and taxes each transaction covers? or just the total amount of the transaction to keep it simple? I'd like to be able to edit as much information as possible if need be, base price, tax rates/amounts, etc. And i'd also like to generate reports on the data(how much of product be was sold, the tax amounts owed, average price each product sold for, etc.) How should i organize all this in my database?
  13. I have a nested array. I'm trying to write code to produce the minimum value foreach first key of the $test array. So, ideally it would produce what's in the $result array. I don't know why i can't figure out how to do this. The multiple nests are throwing me off. I think i'm over thinking this. <?php $test['abcd']['0'] = array('10','100','300'); $test['abcd']['1'] = array('1000','100','3000'); $test['abcd']['3'] = array('23','89','700'); $test['efgh']['0'] = array('3','55','300'); $test['efgh']['1'] = array('160','160','9000'); $test['efgh']['3'] = array('900','89','200'); //$result['abcd'] = 10; //$result['efgh'] = 3; ?>
  14. What's the proper way to check if a file exists on a remote server? I know file_exists() works for you local files. I think i need to use something like the following. BUT if the file is not found PHP throws a warning. I know i can put a '@' before fopen() but that just masks the error. <?php if(fopen("http://www.othersite.com/imageXYZ.jpg", "r")) { echo "File exists."; } else { echo "File does not exist."; } ?>
  15. i would change the very first part to this...for sql injection reasons if (!$_GET['pid']){ $pageid = '1'; } else{ $pageid = (int) $_GET['pid']; if($pageid == 0) { $pageid = "1"; } } So if they do write letters/words in that parameter this would convert it to 0 and then set it to 1
×
×
  • 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.