|
Safety Shaun posted:I was using ip2c (free IP to country database) for a while until it broke. Even the new version keeps breaking, I pasted the errors on pastebin. Looks like you are using a relative path (fopen(../ip-to-country.bin)), do you still get the errors when you use an absolute path? Failing that, maybe try Maxmind's GeoIP database, it's been working great for me.
|
# ? Jun 24, 2008 19:15 |
|
|
# ? May 15, 2024 13:02 |
|
passionate dongs posted:Really dumb question: put the resultset into an array and then have a look at http://www.php.net/json_encode
|
# ? Jun 25, 2008 03:25 |
|
bt_escm posted:put the resultset into an array and then have a look at http://www.php.net/json_encode This works great for encoded arrays for javascript, however I think it requires php 5.2 or higher...
|
# ? Jun 25, 2008 04:23 |
MrEnigma posted:This works great for encoded arrays for javascript, however I think it requires php 5.2 or higher... You can grab json_encode.php off PEAR and just include 'json_encode.php';
|
|
# ? Jun 25, 2008 08:11 |
|
fletcher posted:You can grab json_encode.php off PEAR and just include 'json_encode.php'; Ironically my own advice from earlier in the thread, and not sure why I didn't think of that, thanks for the tip.
|
# ? Jun 25, 2008 14:19 |
|
er0k posted:Looks like you are using a relative path (fopen(../ip-to-country.bin)), do you still get the errors when you use an absolute path? sample.php, geoip.inc, GeoIP.dat all in the same dir (domain.com/ip2c) path in sample.php is correct: $gi = geoip_open("/home/removed/public_html/ip2c/GeoIPCity.dat",GEOIP_STANDARD); Still not working: Warning: fopen(/home/removed/public_html/ip2c/GeoIPCity.dat) [function.fopen]: failed to open stream: No such file or directory in /home/removed/public_html/ip2c/geoip.inc on line 314 Line 314 just includes the var $gi EDIT: Fixed, standard file in the code is GeoIPCity.dat, I just had GeoIP.dat. Safety Shaun fucked around with this message at 17:28 on Jun 25, 2008 |
# ? Jun 25, 2008 16:55 |
|
Safety Shaun posted:sample.php, geoip.inc, GeoIP.dat all in the same dir (domain.com/ip2c) The only way this could be failing is if you have the wrong path. I'm guessing not only do you have a user, but also the domain something like /home/user/domain.com/public_html/ip2c/GeoIPCity.dat Edit: if you have shell access, go to the ip2c directory and type 'pwd' MrEnigma fucked around with this message at 17:45 on Jun 25, 2008 |
# ? Jun 25, 2008 17:32 |
|
Is there anything wrong with throwing a random die() or exit() in a script? The scenario:php:<? if(condition 1) { // do some stuff } elseif(condition 2) { // Do other stuff die(); } else { // Other poo poo } // Here is some code I want displayed if any condition other than condition 2 is met ?>
|
# ? Jun 26, 2008 00:14 |
G-Dub posted:Is there anything wrong with throwing a random die() or exit() in a script? The scenario: If you want code run that matches any condition but condition 2, why not: if (!condition 2) { }
|
|
# ? Jun 26, 2008 00:42 |
|
That depends on the conditions, really. What's the second condition? If it doesn't evaluate to true, whose fault is that? Why would you want your script to just die instead of sending a useful error header and/or message to the user?
|
# ? Jun 26, 2008 00:51 |
|
G-Dub posted:Is there anything wrong with throwing a random die() or exit() in a script? You'll run into problems if another script is dependent on it, but otherwise I don't really see why not. You can die with a useful error message as well.
|
# ? Jun 26, 2008 04:29 |
|
er0k posted:You'll run into problems if another script is dependent on it, but otherwise I don't really see why not. You can die with a useful error message as well. Yeah, it's probably not the best practice as others have said, but really you can do whatever you want (ie php can work that way). I'd recommend throwing an Exception, and potentially catching it someplace else if needed. Although if you don't catch it, you're probably going to end up with a big ugly PHP error on your page.
|
# ? Jun 26, 2008 05:10 |
|
I'm trying to set up a simple PHP script that uploads a file and inserts the filename into an XML document. I have a slideshow system that fetches the image names from the document and puts it up on the slideshow. I'm using DOM XML functions to do this. The problem is, I'm a total newbie with PHP and my host is using an ancient version of PHP (4.1.2). My xml file is structured like this code:
|
# ? Jun 26, 2008 07:18 |
|
Neon Machete posted:I'm trying to set up a simple PHP script that uploads a file and inserts the filename into an XML document. I have a slideshow system that fetches the image names from the document and puts it up on the slideshow. I'm using DOM XML functions to do this. The problem is, I'm a total newbie with PHP and my host is using an ancient version of PHP (4.1.2). There are various backports of different things, like for instance PHP 5's SimpleXML class, has been backported to php4 (although you'll still need the XML parser extension) http://www.ister.org/code/simplexml44/index.html If you get that working, you can use something like: http://us2.php.net/manual/en/function.simplexml-element-addChild.php PHP in general isn't very good in dealing with XML, but with a few tricks you can make it work.
|
# ? Jun 26, 2008 07:28 |
|
fletcher posted:If you want code run that matches any condition but condition 2, why not: That also works I guess, and so simple. The die/exit doesn't occur in a state of error. Essentially I think I have structured my code in a lovely way due to changing my specification every two seconds. Anyway fletcher's method looks like less of a hack so I will go that way. Was just wondering if die/exit resulted in an error in a log or something
|
# ? Jun 26, 2008 10:34 |
|
Frocer posted:Does anyone have or know how to write a script that can grab popular IM online status? e.g. AIM, MSN, Yahoo, etc. Anyone has any idea where to look for this? I have been googling forever and still haven't been able to find anything besides AIM :/
|
# ? Jun 27, 2008 03:34 |
Frocer posted:Anyone has any idea where to look for this? I have been googling forever and still haven't been able to find anything besides AIM :/ Have you tried looking at other open source chat clients to see how they do it? It has been done in many languages, just use a non PHP one to guide you in writing it. This one written in perl would probably be useful.
|
|
# ? Jun 27, 2008 04:23 |
|
A quick one, that is not so much PHP really, than Apache/SAMBA. I want my web application to read a file on a samba share, and display it, but it doesn't work. This might be something silly that I can't see because I'm going crazy over this so if anyone can give me a hint? My DocumentRoot is /var/www/html First I tried to just run: exec("tail /mnt/samba/file",$output); which doesn't work.. So I imagine there is some kind of permission trouble I tried making a link... "ln -s /mnt/samba/file file" in the /var/www/html dir.. and that doesn't work either of course. Making a hard link gives me a " Invalid cross-device link" So what's the easiest way to do this? Is it possible to move the whole DocumentRoot to the samba share? zapateria fucked around with this message at 11:53 on Jun 27, 2008 |
# ? Jun 27, 2008 11:42 |
|
I want to look at designing an application designed to interact with another website. Basically, I want to be able to read data and interact with the other page through PHP. (Automate a control panel which I do not want the user to have full access to) Can anyone point me in the right direction on what I would use to do this?
|
# ? Jun 28, 2008 09:01 |
|
zapateria posted:So what's the easiest way to do this? Try running the commands as the "www-data" user. It'll show you the same errors that PHP is getting.
|
# ? Jun 28, 2008 15:31 |
|
Phiberoptik posted:I want to look at designing an application designed to interact with another website. Basically, I want to be able to read data and interact with the other page through PHP. (Automate a control panel which I do not want the user to have full access to) Can anyone point me in the right direction on what I would use to do this? 1. Use curl to download a page from the other site 2. Curl will return the page source as a string. You can then read through this string using regular expressions, or if it is well formed maybe DOM. 3. After you find what you need in the page, you can then send another request back to the site with curl to post data to forms etc. This could be relatively simple or it could be a total clusterfuck nightmare, it really depends on what you need to do with the other site and how well structured the HTML on that site is. P.S. If the pages change that you are interacting with, it could break your code, so be careful
|
# ? Jun 28, 2008 15:39 |
Phiberoptik posted:I want to look at designing an application designed to interact with another website. Basically, I want to be able to read data and interact with the other page through PHP. (Automate a control panel which I do not want the user to have full access to) Can anyone point me in the right direction on what I would use to do this? I would make sure you aren't breaking their TOS too
|
|
# ? Jun 28, 2008 20:32 |
|
How does preg_match() work for whitespace? I have a bit of ugly code that looks like this, which I'm trying to strip the contents from.code:
code:
|
# ? Jun 29, 2008 06:18 |
Little Brittle posted:How does preg_match() work for whitespace? I have a bit of ugly code that looks like this, which I'm trying to strip the contents from. Load it up into a DOMDocument object and extracting it will be a little easier to maintain. http://www.php.net/dom
|
|
# ? Jun 29, 2008 06:24 |
|
fletcher posted:Load it up into a DOMDocument object and extracting it will be a little easier to maintain.
|
# ? Jun 29, 2008 07:01 |
|
Little Brittle posted:I'm having trouble understanding how you would extract information from elements lacking unique IDs or names with DOMDocument. There are a few things I have to grab by class or by a unique combination of tags wrapping around the data I need. Could you explain how you would use DOMDocument to grab that sort of info? DOMXPath Class XPath Tutorial Example: php:<? $dom = new DOMDocument::loadHTMLFile('example.html'); $xpath = new DOMXpath($dom); // Get a list of all div elements where class = "foo" $list1 = $xpath->query("//div[@class='foo']"); // Get a list of all a elements that are inside p elements $list2 = $xpath->query("//p/a"); ?> DaTroof fucked around with this message at 07:44 on Jun 29, 2008 |
# ? Jun 29, 2008 07:34 |
|
Little Brittle posted:How does preg_match() work for whitespace? I have a bit of ugly code that looks like this, which I'm trying to strip the contents from. It looks like you should probably use the DOMXPATH as DaTroof mentioned, but, to answer your question, your regexp should read: $find_description = '/<div class="description">(.+?)<\/div>/s'; Adding /s will treat the string as a single line. edit: You might find http://www.weitz.de/regex-coach/ to be a useful tool. jasonbar fucked around with this message at 08:47 on Jun 29, 2008 |
# ? Jun 29, 2008 08:44 |
|
Thanks for the help, I got it working.
|
# ? Jun 29, 2008 08:45 |
|
I just started a competition in my forum. Basically people donate their virtual forum money to me, and I convert it to real money, which I donate to different charities. Is there a simple php script that allows me to have a table of the donators which can be easily updated? Maybe I just need something with "Nick, total donated, number of donations" or something more complex if it exists. Thanks.
|
# ? Jun 29, 2008 19:18 |
LastCaress posted:Is there a simple php script that allows me to have a table of the donators which can be easily updated? Maybe I just need something with "Nick, total donated, number of donations" or something more complex if it exists. Thanks. No, I doubt there is, especially one that integrates with your BB software. You will need a bit of programming knowledge to do this and just write your own. Take a look at basic PHP and basic MySQL tutorials.
|
|
# ? Jun 29, 2008 19:29 |
|
fletcher posted:No, I doubt there is, especially one that integrates with your BB software. You will need a bit of programming knowledge to do this and just write your own. Take a look at basic PHP and basic MySQL tutorials. Ah, but I don't need forum integration, I can have a separate table where I manually update it with the nicks and donations!
|
# ? Jun 29, 2008 19:47 |
LastCaress posted:Ah, but I don't need forum integration, I can have a separate table where I manually update it with the nicks and donations! Why do you need anything more than HTML for this?
|
|
# ? Jun 29, 2008 19:56 |
|
I just wanted something that I could easily update, like have a form to input every donation that updated the table automatically.
|
# ? Jun 29, 2008 20:10 |
|
I'm playing around with some PHP to make an RSS reader for a webpage, and I'm having a bit of trouble. If I set the function setHead to echo the input as it sets the variable, it will display, but I recieve nothing from getHeadline();code:
|
# ? Jun 30, 2008 14:58 |
|
LightI3ulb posted:I'm playing around with some PHP to make an RSS reader for a webpage, and I'm having a bit of trouble. If I set the function setHead to echo the input as it sets the variable, it will display, but I recieve nothing from getHeadline(); Your class variables need to be set using: $this->variable_name = whatever; when they're being set inside the class.
|
# ? Jun 30, 2008 15:48 |
|
Oh, I was trying $this->$variable and was getting errors.
|
# ? Jun 30, 2008 16:14 |
|
What is the least resource-intensive method to grab info from an HTML page? Right now I am grabbing the whole page via CURL and finding the data I need via preg_match(), but it looks like DOMXPATH will work just as well. I'm trying to grab info on the fly from various websites, and I'd like to make it as efficient as possible. Could anyone elaborate on keeping this process lean?
|
# ? Jul 3, 2008 19:51 |
|
Little Brittle posted:What is the least resource-intensive method to grab info from an HTML page? Right now I am grabbing the whole page via CURL and finding the data I need via preg_match(), but it looks like DOMXPATH will work just as well. I'm trying to grab info on the fly from various websites, and I'd like to make it as efficient as possible. Could anyone elaborate on keeping this process lean? I just open the url straight to TinyHTML to convert it into valid XHTML which I then import into SimpleXML and run an XPATH against it. If you can't turn on furl wrappers, you'll need to use curl to get the page first.
|
# ? Jul 3, 2008 20:05 |
|
I'm having a strange problem with PHP and APC. I have 2 servers running CentOS 5; on one, APC compiled, installed, and ran without a problem. On the other, it gives me this during the setup: code:
code:
(edit for really, really long line) Edit: Fixed. For some reason, this one had everything except for mod_php at 5.2.4, while mod_php was 5.1.6. I have no clue why. aehiilrs fucked around with this message at 01:00 on Jul 4, 2008 |
# ? Jul 3, 2008 23:13 |
|
|
# ? May 15, 2024 13:02 |
|
duz posted:I just open the url straight to TinyHTML to convert it into valid XHTML which I then import into SimpleXML and run an XPATH against it. If you can't turn on furl wrappers, you'll need to use curl to get the page first. I have another question, how do you get the value of an attribute via XPATH? I have an xml file that looks like this, and I'm trying to grab the ref[href] value (hello.php). Nothing I've tried doesn't seem to be working, and I can't find any good tutorials on it. code:
|
# ? Jul 4, 2008 21:29 |