Jump to content

tomccabe

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

tomccabe's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have an XML file like such: <spice> <sections> <contact></contact> <products></products> <people></people> <homes></homes> <harvest></harvest> <contactCopy> <banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners> </contactCopy> <homesCopy> <banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners> </homesCopy> <productsCopy> <banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners> </productsCopy> <peopleCopy> <banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners> </peopleCopy> <harvestCopy> <banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners> </harvestCopy> </sections> </spice> What I need to be able to do is pull the CDATA content out, WITH the tags intact, have the client edit the content with a markup editor and put unentitied HTML back into the CDATA section. Sorry for being all over the place! I've been up all night trying to solve this stupid problem for a stupid Flash site.
  2. $doc = new DomDocument(); $file = "spice.xml"; $doc->load($file); $homesCopy = $doc->getElementsByTagName("homesCopy")->item(0); $banners = $homesCopy->firstChild; $doc->removeChild($banners); "Argument 1 passed to DOMNode::removeChild() must be an instance of DOMNode"
  3. Yup, I've been looking at this, but it's all very confusing. I have a deadline of today and the only thing I can't get to function is the CDATA section. Starting to freak out because most of my searching leads me down wildly different paths, some with "createCDATASection", some using an XPath object, some traverse the document with getElementByTagName...I am able to echo the CDATA section I want to be able to edit, but can't seem to get removeChild to work (granted I'm trying to absorb all of this at a rapid pace). Here's what I have so far: $doc = new DomDocument(); $file = "spice.xml"; $doc->load($file); $xPath = new DomXPath($doc); $homesCopy = $xPath->query("//sections/homesCopy"); echo $homesCopy->item(0)->nodeValue; I get the tags in the CDATA section to output as html here which is great. Now if only I could edit it
  4. If I don't use that option none of the text from the CDATA sections is pulled out on the load.
  5. I'm tearing my hair out trying to work with "simple" XML for the first time. I'm building a small CMS for a Flash based site and the content is held in an XML file. My problem is that many of the copy fields are XML CDATA fields. On the one hand, with: $xml = simplexml_load_file($file, 'SimpleXMLElement', LIBXML_NOCDATA); I can pull the data out of that node and the CDATA tags are stripped. My issues come with trying to save the data with: file_put_contents($file, $xml->asXML()); Problems are: a) tags are interpreted with their HTML entity equivalents. I don't want this to happen as it's a CDATA field being read by Flash. I gather this is coming from the asXML method because even if I do an html_entity_decode on the $_POST data it's still being converted. b) because of the above, there's no way to add the CDATA tags because they also have their charachters converted. SimpleXML so far has been anything but simple for me Has anyone ever run into this? Is there a way to save the file back in a way that will just keep my data exactly as is and also allow me to add the CDATA tags back in?
  6. I set the first condition of the while loop for a state matching the GeoCity state (the only other field they share) and that's shaved a little bit of time off (getting about 3500 - 5500ms on firebug now), but now my interest is also peaked! This stupid banner is actually turning into a fun little project haha.
  7. Yeah, porno, you are absolutely correct. Unfortunately this banner is one that will display the weather at the user's location and that API needs zip code data, not simply city. I had no problem getting the city data as soon as HTH pointed me to GeoCity. The problem is that they only have zip codes for about half their records. Not too helpful a majority of the time (for instance no zip for me in Hollywood or partner doing the Flash portion in NYC). That said, I did solve my problem and will post my solution for anyone else that might come across this here or through Google (and feel free to tell me if it could be more efficient! I'm sure there are ways I might cut down on query time of the CSV). I did indeed do it by latitude and longitude and used the CSV file with zip codes/lat/lon located here (as suggested by GeoCity FAQ): http://geocoder.ibegin.com/downloads.php The script cuts out before using the CSV if the IP has a zip code record in the GeoCity database, so it only adds the query time if it absolutely needs to (and it is about a full second). <?php include("geoipcity.inc"); include("geoipregionvars.php"); // OPEN GEOCITY DATABASE $gi = geoip_open("GeoLiteCity.dat",GEOIP_STANDARD); // IP CHECKS if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } // GET GEOCITY LOCATION DATA FROM IP $record = geoip_record_by_addr($gi,$ip); // IF ZIP IS LOCATED IN GEOCITY DATABASE, RETURN if ($record->postal_code) { return $record->postal_code; } // IF NOT RESOLVE ZIP CODE BY LATITUDE/LONGITUDE & RETURN else { $lat = $record->latitude; // save GeoCity latitude $lon = $record->longitude; // save GeoCity longitude $row = 0; // start at first row of zip code file $diff = 10; // init out of bounds difference $open = fopen("zips.csv", "r"); // open zip code file while (($data = fgetcsv($open, 1000, ",")) !== FALSE) { // check records $test = abs($data[3] - $lat) + abs($data[4] - $lon); // get total difference between this record and actual lat/lon if (($test < 10) && ($test < $diff)) { // if it's reasonably close and less than the current lowest $diff = $test; // reset lowest record $zip = $data[0]; // set this zip as current } } return $zip; } // IF NO RESULT FROM EITHER, RETURN NYC DEFAULT if ($zip == NULL) { $default = "10001"; return $default; } geoip_close($gi); ?>
  8. After a bit more digging I found the fgetcsv() function. Seems to be what I'm after. Here's the steps I think this needs to take: 1. Run ip search on geoip database. 2. if {find match with zip} return zip -task complete in this case 3. else {take lat/long from geoip. Run csv query on csv file. Check each entry's lat/long. Get sum of abs value of difference between lats and abs value of difference between long. Return zip from record with lowest total difference. The portions in bold which specifically deal with the csv records is where I'm stumped. The examples in the php manual are not all that helpful for my situation.
  9. Hey HTH, This was great...gives me *almost* what I need. I've got it looking up city/state at this point, but their database doesn't actually have zip codes. They explain this as such: The site this points to has a great csv file with zip codes that is totally fine (weather difference won't be that crazy if I'm off by 25 miles...it doesn't need to be a scientific match). Throughout searching I've vaguely gotten the idea that you can run an SQL query on a csv file (maybe I'm getting that wrong). I do know you can import one into an SQL database, but as this will be an advertisement the server won't necessarily have SQL installed. What are my options? I'm so close I just need to figure out how to interface these 2 pieces of data! Arrrghhhh!!!
  10. I have to write a script for some banners that need to be returned the user's zip code...anyone have any idea how to do this? :'(
  11. I have a couple specific questions as I work to get more efficient/complex with my MySQL queries. In this specific project I have 3 related tables: products, categories and prod_cats. The last table functions essentially as a go between for category and position values (i.e. each product can be in multiple categories and has a specified position in each category). - 1st question: I have working PHP methods that add new categories and products. For instance the category one finds out how many rows are in the categories table in one query and assigns that value+1 to a variable, then adds that as the position, plus the category name to the table in another query. What I would like to do is roll this into one query. I tried things along the lines of: INSERT INTO categories (category, position) VALUES ('$category', (SELECT MAX(position) FROM categories)+1) This returned the error: "You can't specify target table 'categories' for update in FROM clause". It would be helpful to find any way to do this sort of operation. - 2nd Question: Well I answered this while posting this, but I thought I'd post where I found it in case it helps someone else. I was trying to find uncategorized products (no rows in the prod_cats table would have that product ID but the product does exist). This is for orphaned products after categories are deleted, etc or for products that the client doesn't want to bother categorizing while entering a batch. Obviously there's tons of other reasons to want to find something that is in one table but not another in relational databases. It uses NOT IN plus a subquery (it doesn't make a ton of sense to me why the subquery there does what it does, but hey, I'm learning). http://ocaoimh.ie/mysql-finding-the-records-in-one-table-that-are-not-in-another-table/
  12. Should I be doing more than this?
  13. I'm using sessions, yes. Security is a pretty new and confusing topic for me. I register a session variable when someone logs in and each page checks to see if that variable is set.
  14. I'm working through SSL stuff for the first time. I just want to know if I should secure my entire CMS or simply the login page? The only thing really happening in the CMS is adding/editing products for a store. Actually, there's the ability to view/print orders, but not edit the info. I know on the client side that I'll be securing my login/register/checkout pages, but I'm a little confused on how much of the backend needs SSL.
  15. I think I've found the solution to this. Paypal's Website Payments Pro API. Looks like a giant pain, but it achieves the intended purpose.
×
×
  • 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.