|
duz posted:You can use a combination of HTMLTidy to clean up the HTML and SimpleXML to search the document. That's useful if you are parsing an entire html document or a whole bunch of different tags, but if it was a one-time thing I'd probably just use php:<? preg_match("/<h1>(.*?)<\/h1>/s",$string,$h1); $contents = $h1[1];?>
|
# ¿ Mar 22, 2008 18:49 |
|
|
# ¿ Apr 29, 2024 10:33 |
|
Treytor posted:Alright I am a total newb at PHP and coding, and frankly I can't wrap my head around it. But I'm having a problem: php:<? checkLog($REMOTE_ADDR,$ipLog,$timeout);?> php:<? checkLog($_SERVER['REMOTE_ADDR'],$ipLog,$timeout);?>
|
# ¿ Mar 25, 2008 04:00 |
|
Treytor posted:Wow, that was easy. Thank you sir! Haha, no problem. Mistakes like that tend to be extra difficult to catch when starting out. Unsureness leads to checking the logic of your code 30 times over before realizing that it was just a stupid typo. Scaevolus posted:Be aware that this is a very inefficient way to do this, and it would be better to use a database. I'm assuming he's just trying to learn how to program or something, not implement this (I hope).
|
# ¿ Mar 25, 2008 04:38 |
|
cka posted:Also, I'm not too sure if it would matter or if it's just the OCD freak in me, but your math could use a quick fix here: Well then apparently your mind doesn't follow simple PEMDAS (and it really, really should if you're working with programming languages). I like the first version much better personally; it's not cluttered with extraneous parentheses. admiraldennis fucked around with this message at 08:46 on Mar 25, 2008 |
# ¿ Mar 25, 2008 08:43 |
|
DaTroof posted:They're equal in practice because the multiplication is performed before the addition. They're equal. End of story. ($now < ($subdata[1]+3600*$timeout) && $ip == $subdata[0]) is in no way ambiguous.
|
# ¿ Mar 25, 2008 08:48 |
|
cka posted:Just my OCD then, no harm no foul. Also, just FYI, I actually was following BEDMAS (same thing as PEMDAS, evidently) with those extraneous brackets around the 3600 * $timeout. cka posted:in my mind, the first equation would be a loving huge number if your timeout was 2 hours because it would basically multiply the time + 1 hour by two...
|
# ¿ Mar 25, 2008 09:15 |
|
Treytor posted:Well... I am looking to implement this. I realize a sql database would be much better, but that is WAY beyond me at the moment. One step at a time here... You sound like you're in a little bit over your head here. Let me guess, this is for that "prank call people from the internet" thing? I think I recognize you. If so, you should probably consider paying somebody to do the code correctly for you instead of asking a bunch of questions here just so you can use some crappy file database that's going to choke to death if your site ever gets a lot of traffic. admiraldennis fucked around with this message at 09:22 on Mar 25, 2008 |
# ¿ Mar 25, 2008 09:18 |
|
DaTroof posted:I disagree. One of the benefits of using classes is the ability to use simple, descriptive member names that won't collide with the same name in other contexts. If $obj->delete() is an appropriate name for what the function does, I'd use it. The fact that it's obviously an object member instead of a global function should eliminate any confusion. I agree, though delete() isn't even a built-in function...
|
# ¿ Mar 28, 2008 06:20 |
|
minato posted:Yes it is: http://jp2.php.net/manual/en/function.delete.php Good job reading the page you linked quote:This is a dummy manual entry to satisfy those people who are looking for unlink() or unset() in the wrong place.
|
# ¿ Mar 28, 2008 06:59 |
|
Foolio882 posted:True, but getting rid of my "html nonsense" changes nothing as well: You clearly have some fundamental misunderstandings here. What are you trying to accomplish? What does displayPictureTable output? By specifying a content-type of image/jpeg, you are telling the browser that the entire document you are producing is a jpeg image. The only output should be binary image information, such as that outputted by gd's image creation functions. You can't simply spit the binary contents of an image from a gd function into the middle of an html document and expect an image to appear.
|
# ¿ Mar 31, 2008 21:21 |
|
Foolio882 posted:Oh dear god I think I'm hosed, as the function name suggests, this is supposed to be outputting a picture table and it's loaded with required html. Web browsers request and load images separately from HTML. I'd probably stick the resize image code in another php script; let's call it makeThumb.php for example. makeThumb.php takes in an image filename via GET and outputs the resized version. The displayPictureTable function would output a table containing HTML that refers to images generated by makeThumb.php, for example: php:<? foreach($imgarray as $img) { echo "<img src=\"makeThumb.php?img={$img}\"><br>"; }?> An elegant solution might include <img> tags that refer to images directly as if they already existed in a thumbnail directory (e.g. <img src="/img/thumbs/pic1.jpg">). If the appropriate thumbnail already exists, it will be loaded per normal. If not, a simple 404 redirection could point to a thumbnail generation script that would fetch the original image ('/img/pic1.jpg'), return the resized one to the browser, and then store the resized one in the thumbs for later use. admiraldennis fucked around with this message at 22:01 on Mar 31, 2008 |
# ¿ Mar 31, 2008 21:52 |
|
Foolio882 posted:If it can be done automatically, I'm all for it and that will work just fine and dandy. I just did a bit of quick googling and found some very relevant information, and hopefully this will all come together nicely. Yeah, this is all pretty basic knowledge stuff. Did you read/comprehend my post?
|
# ¿ Mar 31, 2008 22:15 |
|
Foolio882 posted:The one part of your post I didn't fully comprehend was "a simple 404 redirection could point to a thumbnail generation script that would fetch the original image ('/img/pic1.jpg'), return the resized one to the browser, and then store the resized one in the thumbs for later use. " I understand the goal there, and think it would work very well, but can you clarify what I've bolded? Is that what you already talked about with the makeThumb.php script? By "a simple 404 redirection" I meant a system to redirect 404 errors that occur during requests to documents the thumbs directory to a specific php script. If the server was apache, you'd place an .htaccess file in the '/img/thumbs/' directory containing something like: code:
admiraldennis fucked around with this message at 22:58 on Mar 31, 2008 |
# ¿ Mar 31, 2008 22:56 |
|
Treytor posted:This is an ip logger and checker, which outputs to a text file on the server. Is there a more efficient way to do this? Say for example if my site was getting hammered and my host was complaining about the PHP slowing down the entire server... Let me quote myself from a few pages ago: admiraldennis posted:you should probably consider paying somebody to do the code correctly for you instead of asking a bunch of questions here just so you can use some crappy file database that's going to choke to death if your site ever gets a lot of traffic. I know you "want to do it yourself" but seriously if your site is getting hammered and your host is complaining just buck up and either 1) go learn to do this with a database, or 2) have somebody else do it for you and study the code and db schema to figure out how it works. admiraldennis fucked around with this message at 08:37 on Apr 2, 2008 |
# ¿ Apr 2, 2008 04:52 |
|
Finite posted:... Thats the only way one should include variables within a double-quoted string, in my opinion. Either that or with a concatenation. It's borderline ambiguous otherwise and hurts readability.
|
# ¿ Apr 4, 2008 21:51 |
|
Zorilla posted:I think the PHP documentation says the same thing. In other words, something like this? That's what I usually do if magic quotes is on.
|
# ¿ Apr 7, 2008 17:42 |
|
drcru posted:How do I search for <br /> with preg_match_all? preg_match_all("/<br \/>/i",$in,$out); (case-insensitive, will only match <br /> and not <br>)
|
# ¿ Apr 9, 2008 05:19 |
|
drcru posted:Can I assume that #\n# will find all new lines? Yes. If you have any more questions you should probably just google a regular expressions tutorial.
|
# ¿ Apr 9, 2008 05:37 |
|
gibbed posted:If you're serious about using a regular expression to find newlines, you probably want #\r?\n|\r# instead. You should probably just normalize newlines from the get-go with something like: $str = str_replace(array("\r\n","\r"), "\n", $str); especially since PCRE by default understands \n as the newline character admiraldennis fucked around with this message at 06:21 on Apr 9, 2008 |
# ¿ Apr 9, 2008 06:19 |
|
|
# ¿ Apr 29, 2024 10:33 |
|
genericadmin posted:Or, if you want to be flexible... Don't you mean: preg_match_all("#<br(?: /)?>#", $string, $m) edit: can't quote your < admiraldennis fucked around with this message at 12:08 on Apr 9, 2008 |
# ¿ Apr 9, 2008 12:01 |