Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. ...and...? There's a million reasons that could happen. You could have forgotten to put the correct url in $url. You could have typoed when putting the url in $url. You could be trying to scrape a page that doesn't have <em>...</em> tags. Your server could be setup to not even allow file_get_contents. In other words, be more specific when posting a problem. You can start by posting the url you are trying to scrape and how you specifically integrated that code into your script, because I'm not psychic.
  2. .josh

    PHP Form

    You still need the "..." with php stuff sometimes. Not with "php stuff sometimes". php has nothing to do with it. You need it for your html form to recognize it 'sometimes.' php will parse it and send results to the browser, so it's your browser deciding what to do with this: ... value=test ... vs. ... value="test" ...
  3. thread closed. This is not a php question and you are not allowed to post the same thing in multiple areas. Just pick the one you think it's most closely related to and post there. If it needs to be moved, we'll move it.
  4. You can possibly use curl to send data/receive response. Or you could possibly use file_get_contents and some regex. Depends on what you mean by "That function then does its business and outputs an array of values."
  5. Not tested but, here's the idea: <?php $url = "http://www.somesite.com/page.php?id="; // site to scrape $page = 1; // page to start at $exists = true; // loop control // begin loop while ($exists == true) { // get contents of target page $content = file_get_contents($url . $page); // check if current page is same as prev page $exists = ($content == $prevContent)? false : true; // grab everything between all em tags preg_match_all('~<em>(.*?)</em>~', $content, $matches); // assign results to an array of $page position $matchedPages[$page] = $matches; // assign current page as prev page for next loop iteration $prevContent = $content; // inc page $page++; } // end while // echo out results echo "<pre>"; print_r($matchedPages); echo "</pre>"; ?> CAUTION: This could easily make an infinite loop!. The idea is that you keep iterating $page and try to find out if there are no more pages to scrape by checking the current page scrape against the previous one. But if there is dynamic content being generated on the page that changes each page load (like, current time, some random quote, ad rotations, etc..) this will not work, because this would technically make the page unique. So this code is a starting block. Your task will be to look at the 'page not found' or 'error page' or whatever page is defaulted to when there are id=xx doesn't exist, and find an identifier that doesn't change. You will probably have to preg_match for it.
  6. You need to post an example of the string you are trying to regex. There's no way we can tell you what's wrong with your regex without knowing what the subject of the regex is. What I can do is tell you what your current regex is doing. #<div id="result"><div[^>]+>(.+?)</div># It is looking for a div tag that looks exactly like this: "<div id="result">" If there is anything else in that tag or if the format is different in any way that that literal text, it will not match. If it matches, it then looks for a div tag immediately after it (no whitespace, new lines, other text, nothing). This 2nd div tag can have anything in it. If it gets this far, then it will capture everything up to the first </div> it encounters.
  7. I did say that earlier, but I was under the impression he wasn't a resident of that country. I'm all for questioning the rules, even if it's my friend's rules. And I'm even pro-breaking them if I'm being forced to live by them (if I feel they are somehow morally wrong, or maybe if they are just stupid. Depends on the severity of the 'moral' infraction vs. severity of the punishment for breaking them). I relented and restated on that count 2 posts ago. And that's only an option if you happen to have serious oil reserves. Haha true LOL.
  8. Yes, that is true, but that's a different kind of validation. You want to validate the format to make sure someone isn't trying to enter malicious code. You then want to validate it as an email address user has access for various other reasons, like identity confirmation (not some spambot), communication (newsletters, etc..), security (password resets, etc..). Sure, you could look at it as "if I request email confirmation they have to access email address and therefore it has to be valid format anyway so why bother with the extra step in format validation?" Your script doesn't wait for the user to validate the email address before putting the info into the database. It puts the info (including the email address) into the database right then and there, along with the validation code and some kind of "on/off switch" column specifying whether email was verified or not. When user gets the email and clicks the link or enters in validation code or whatever you do to confirm it, the "on/off switch" column is switched to signify that it has been validated. That's more or less how it goes. But the point is that you can't depend on email format validation by virtue of getting a response from user from something in the email, you would already have that email address in your database. So if you go that route, you would be entering data into your database whose format has not been validated. That leaves a hole open for people to attack your site through the email form field. You could then argue "Okay why not just use mysql_real_escape_string on it (and everything else) and call it a day?" Yes, you could. But that only prevents potential sql injection (most of the time, not always). Beyond that, it does nothing as far as you controlling what format you want users to submit data in. For instance, perhaps you only want to accept .com email address for some reason. mysql_real_escape_string does nothing to validate that. Or say you want users to be able to pick an alphanumeric username. How does mysql_real_escape_string enforce that? It doesn't. You need to use other things to validate the format anyway. So if you are for instance, already checking to make sure that a user's name is only alphanumeric with some regex, then mysql_real_escape_string becomes superfluous. There won't be any potential quotes to escape because your regex would have caused it to fail already. And going back to email validation. What if user typoed his email address? Forgot the dot in frank@blahcom? He would never get his email confirmation because of that typo, which you could have caught by checking that it was at least the right format.
  9. unfortunately doing something about it is not easy. You can hope that some other country/countries (coughamericacoughcough) decides your government is terrorist and needs to go down. Or you can move. If you're even allowed to in the first place. And even if you are, it's still not that easy to just pick up and move to some other country. You might have history, family/friends, culture, traditions, family business or land, etc.. list goes on and on. obey the government, no questions asked, eh? Kind of funny, coming from an american.
  10. You have a bunch of spaces in your regex that shouldn't be there.
  11. You can't do it with php alone. You can retrieve the number from your db and pass it to javascript and javascript can do the 'live' countdown.
  12. If you want to make an online "community" as simple as possible, incorporating a database, just make a guestbook.
  13. mmm...then no, I don't support that. I subscribe to the idea that you are responsible for your own actions. I think my opinions might have been confused with that by the parallel running thought of what corbin pretty much said: mess with fire and you might get burned.
  14. mysql_real_escape_string sucks. Be a man. Use regex. It'll put hair on your chest.
  15. I don't know, am I? If that's the definition of agentic behavior, then no, I don't necessarily support that. But then again, sometimes I do. Life is a bit more complex than that, and things should be judged on a case by case basis, imo. In the context of this discussion, I admit that I somewhat misunderstood the OP. I thought he was some random Joe website owner outside of china, hence the "going to a friend's house" analogy. But it seems that he is in fact, a resident of china. So a better analogy would be if he was living at home under his parents' roof and they are enforcing house rules and he can't just walk away, because he lives there. So...since he is indeed being forced to live by those rules, then I do (somewhat) sympathize. My reason for saying 'somewhat' can best be summed up with what akitchin and corbin said: But then, I do hastily add on to that that I'm not a resident of china, never been, probably never will be or ever will go to china, so the OP is in a much better position to accurately gauge living conditions there. On the other hand...seeing as how virtually all of my country's debt is to China, it's not entirely unreasonable to imagine them as our future overlords, so maybe I will indeed find out what it's like to walk in your shoes one day
  16. oops. $sql = "SELECT `id`, `date`, `start_time`, `lenght`, `client_first`, `client_last`, `city`, `host`, `status`, `note`, ADDTIME(`start_time`,`lenght`) as endtime FROM booking WHERE host='$host' AND city='$city' ORDER by `date` AND `start_time`";
  17. .josh

    PEAR

    If you are running php version 4.3.0 or higher, it comes already installed, and you should be able to use it (unless someone specifically compiled your php to run without it).
  18. $sql = "SELECT `id`, `date`, `start_time`, `lenght`, `client_first`, `client_last`, `city`, `host`, `status`, `note`, (`start_time` + `lenght`) as endtime FROM booking WHERE host='$host' AND city='$city' ORDER by `date` AND `start_time`"; . . . $endtime = $data['endtime'];
  19. Buzz kill. It was both a joke and a simplified explanation, as I figured saying all that to the OP would roughly translate to "It's your date stored as the number of seconds since blah blah blah analretentivewhywon'tthisguyshutup moreblah wtfdoesallthatmeananywayz lolzblahblah".
  20. It means the regex failed so there's no $yourpost3[1] defined.
  21. yeah except you aren't campaigning to get rid of the censorship/oppression...you're just wanting to skirt the rules for your own random site.
  22. That format is a unix timestamp. It's your date stored as the number of seconds since the beginning of time.
  23. You might have some luck with certain advertisers if your random pics were of a "You must be 18+ to enter" nature.
  24. You know, I saw that manual entry. glob doesn't recognize the +. Only * or ? but from a shell context. Like in a shell context, ? is really like a dot (.) in that it matches any one character (other than a new line) and * is the same: 0 or more. But + (1 or more) is not supported. I tried it even from a bash prompt and no dice on the +. So yeah, that user comment is wrong. Also * acts on its own accord. So for instance, if I did a*.php the * is independent of the 'a'. glob("a*.php") will return all of the following, but the * itself will only match: a.php // * matches nothing aa.php // * matches the 2nd a ab.php // * matches 'b' abc.php // * matches 'bc' As far as the ? goes, like I said, it's really like a "pcre" dot (.) in that it matches any one character (not 0 or 1) so if you did glob("a?.php"); against a.php aa.php ab.php abc.php aa.php and ab.php would be returned.
  25. On a positive note, it seems like a chance to immortalize yourself in the php manual, by posting an entry explaining what exactly is allowed Because I'm gracious and generous, I will allow you to have that honor. My infamy already causes me to beat off the women with a stick
×
×
  • 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.