|
Daddy Fantastic posted:Are there any benefits to using MDB2, assuming I'm already using mysqli prepared statements, won't be switching away from mySQL, and I'm not already using PEAR? If you're already using prepared statements, then probably not.
|
# ? Mar 22, 2008 19:47 |
|
|
# ? May 16, 2024 17:31 |
|
Lumpy posted:If you are using PHP5, and your HTML is valid XML (which it might (probably?) not be) you can do it easily like so: Ah! I tried to use the DOM functions but it was barfing all over the html. This simplexml thing seems a lot more. . . simple. edit: Well simplexml is not liking it either, even after running it through tidy. I think the html is just too big of a mess. I am trying to use preg_match("/<h1>(.*?)<\/h1>/s",$string,$h1); now but I get an error about the regex string: Unknown modifier 'h' edit2: haha, there was a slash in there that you can only see when quoting. It works now! other people fucked around with this message at 21:13 on Mar 22, 2008 |
# ? Mar 22, 2008 20:47 |
|
Standish posted:You also can't do just do (functionthatreturns() == "") see: php:<?php function what($return) { switch( $return ) { case "boolean": return true; break; case "string": return "string"; break; case "integer": return 1; break; case "array": return array("hello", "goodbye"); break; case "nothing": return; break; } } if( what("boolean") == "" ) { echo("what(bool) = nothing<br />"); } if( what("string") == "" ) { echo("what(string) = nothing<br />"); } if( what("integer") == "" ) { echo("what(int) = nothing<br />"); } if( what("array") == "" ) { echo("what(array) = nothing"); } if( what("nothing") == "" ) { echo("what(nothing) = nothing"); } ?> what(nothing) = nothing
|
# ? Mar 23, 2008 05:38 |
|
LOL AND OATES posted:yikes Careful there. There is no such type in PHP as 'nothing', that use of return with no value actually returns NULL, and NULL, 0, and false are all equal to "".
|
# ? Mar 24, 2008 16:40 |
|
Mashi posted:Careful there. There is no such type in PHP as 'nothing', that use of return with no value actually returns NULL, and NULL, 0, and false are all equal to "".
|
# ? Mar 24, 2008 16:55 |
|
Mashi posted:Careful there. There is no such type in PHP as 'nothing', that use of return with no value actually returns NULL, and NULL, 0, and false are all equal to "". Oh yeah I know I was just being lazy.
|
# ? Mar 24, 2008 20:14 |
|
I've just playing with CodeIgniter and have already ran into a problem. I'm trying to load a model from my controller and I'm getting this error:code:
My controllers are in the application/controllers folder. The views are in the application/views folder. And the models are in the application/models folder. Any idea what's going wrong or why it's looking for Test_model in the Loader.php file?
|
# ? Mar 25, 2008 02:10 |
|
Gary the Llama posted:I've just playing with CodeIgniter and have already ran into a problem. I'm trying to load a model from my controller and I'm getting this error:
|
# ? Mar 25, 2008 03:41 |
|
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:code:
This correctly keeps the log, but it won't block the user out. What am I doing wrong?
|
# ? Mar 25, 2008 03:48 |
|
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 |
|
Wow, that was easy. Thank you sir!
|
# ? Mar 25, 2008 04:11 |
|
Treytor posted:Wow, that was easy. Thank you sir!
|
# ? Mar 25, 2008 04:16 |
|
Okay, now how would I display inline the amount of time remaining per IP? For example, taking the ip log recorded from above and in a new page I would have: code:
Treytor fucked around with this message at 05:02 on Mar 25, 2008 |
# ? Mar 25, 2008 04:31 |
|
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 |
|
admiraldennis posted:I'm assuming he's just trying to learn how to program or something, not implement this (I hope). 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...
|
# ? Mar 25, 2008 04:46 |
|
PHP noob alert! Oh god please don't rape me in the rear end The script I'm using for news posting is designed so the comments for each news item are displayed with links like "/news/comments.php?action=list&newsid=1" but I'd like to have the comments displayed below each post, rather than on a separate page. There doesn't seem to be a variable to do this with the templates, so how can I accomplish it? The script is available for download at http://www.utopiasoftware.net/newspro/dl.php?filename=newspro140b.zip&mirror=1 Perhaps there's a better script I should use instead? I don't need a cms script though, just a way to include blog posts on an otherwise static website.
|
# ? Mar 25, 2008 06:11 |
|
Treytor posted:Okay, now how would I display inline the amount of time remaining per IP? The simplest way would be to record both the current time and the time + 3600 seconds in your log file, and change banned.html to banned.php (and/or just incorporate your banned notice in that php script itself... subtract 1-hour-in-the-future time from current time, divide by 60 and ceil() the result to have your remaining minutes.) Another simple way would be to record the time information in the users' cookies via setcookie() and bang out some javascript that does it client-side, although that can be pretty easily side stepped. I gotta say though, using a SQL database (even if your table is of poor design, though it probably wouldn't effect it speed-wise for something like this) really would be leagues better than this file i/o and array madness you've got going here. 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: if ($now < ($subdata[1]+3600*$timeout) && $ip == $subdata[0]) should be if ($now < ($subdata[1]+(3600*$timeout)) && ($ip == $subdata[0])) 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 08:23 |
|
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 |
|
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: They're equal in practice because the multiplication is performed before the addition.
|
# ? Mar 25, 2008 08:47 |
|
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 |
|
admiraldennis posted:Well then apparently your mind doesn't follow simple PEMDAS (and it really, really should if you're working with programming languages). 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. edit: well then cka fucked around with this message at 09:20 on Mar 25, 2008 |
# ? Mar 25, 2008 09:14 |
|
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 |
|
admiraldennis posted:You sound like you're in a little bit over your head here. Yeah, you're right. The problem is I don't have any resources to hire anyone, and I'm also fairly interested in learning a bit about this stuff. If this site proves a worthy venture, then I'll look into more appropriate options down the road.
|
# ? Mar 25, 2008 09:30 |
|
Gary the Llama posted:I've just playing with CodeIgniter and have already ran into a problem. I'm trying to load a model from my controller and I'm getting this error: The Loader.php file contains the code that is run when you do $this->load->whatever() so that is why it's showing you the error there. My guess is that there is an error in your Model that is keeping it form being run as a class. Replace your code with this: php:<? class Test_model extends Model { function Test_model() { parent::Model(); } } ?>
|
# ? Mar 25, 2008 14:27 |
|
gi- posted:So I just upgraded my hosting environment. Went from PHP4 to PHP5 and getting this error 'Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource' PHP.net posted:For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
|
# ? Mar 25, 2008 16:14 |
|
Is there a fancy one line PHP trick that could replace this foreach loop?code:
|
# ? Mar 25, 2008 18:15 |
|
Dear god somebody please help!php:<?php echo "test"; $im = createfromjpeg('../images/test.jpg'); if (!$im) { die ('Unable to open image'); } echo "Image Opened"; ?> test Fatal error:Call to undefined function createfromjpeg() at line whatever GD Version 2.0.34 is installed, with jpeg support. Anyone have any ideas? Once I get this poo poo worked out I can actually start this project
|
# ? Mar 25, 2008 18:59 |
|
Foolio882 posted:Dear god somebody please help! imagecreatefromjpeg()?
|
# ? Mar 25, 2008 19:07 |
|
Hey, whatdya know, I'm an idiot. Thanks!
|
# ? Mar 25, 2008 19:22 |
|
Daddy Fantastic posted:Is there a fancy one line PHP trick that could replace this foreach loop? php:<? if (in_array($password, $b)) { // whatever } ?>
|
# ? Mar 25, 2008 19:28 |
|
duz posted:
|
# ? Mar 25, 2008 20:08 |
|
Daddy Fantastic posted:I'm not sure that will work though, since $password could be any length-- in other words, I'd like it to match words that include the banned words, but may contain other letters (like dookieq). In that case no, the only other way I can think to do it would be to use a callback function with something like array_filter but that would take about the same amount of lines. Edit: Or you could collapse the array to a single string but that could introduce false positives.
|
# ? Mar 25, 2008 21:13 |
|
OlSpazzy posted:PHP noob alert! Oh god please don't rape me in the rear end Ok well I hacked parted of the news.php script to include sections from comments.php relevant to listing comments. I'm using the $comments_list_commentbit variable in the news_newsbit_commentslink template, but I'm only getting one comment out of 5 in the database showing up, and it's showing on the wrong newsid. Any ideas? php:<? if ($action == '') { define('ISPRINTABLEPAGE', false); define('WILLTRUNCATE', true); define('ISRSS', false); $templatesused = 'news_newsbit,news_newsbit_commentslink,news_avatarbit,news_newsbit_readmorelink,comments_list_commentbit'; unp_cacheTemplates($templatesused); $getnews = $DB->query("SELECT * FROM `unp_news` ORDER BY `date` DESC LIMIT $newslimit"); while ($news = $DB->fetch_array($getnews)) { $catid = $news['catid']; $category = $categorycache["$catid"]; $newsid = $news['newsid']; $subject = $news['subject']; $newstext = $news['news']; $poster = $news['poster']; $posterid = $news['posterid']; $date = $news['date']; $postdate = unp_date($dateformat, $date); $posttime = unp_date($timeformat, $date); $avatar = unp_checkAvatar($posterid); if (!$avatar) { $useravatar = ''; } else { eval('$useravatar = "'.unp_printTemplate('news_avatarbit').'";'); } if ($commentsallowance == '1') { $comments = $news['comments']; eval('$commentsinfo = "'.unp_printTemplate('news_newsbit_commentslink').'";'); } else { $commentsinfo = ' '; } $comments = $news['comments']; //$newstext = $n->unp_doNewsTrim($newstext); // Move to unp_doNewsFormat $newstext = $n->unp_doNewsFormat($newstext); $subject = $n->unp_doSubjectFormat($subject); // NewsBit eval('$news_newsbit = "'.unp_printTemplate('news_newsbit').'";'); unp_echoTemplate($news_newsbit); // NewsBit echo "\n\n"; $getcomments = $DB->query("SELECT * FROM `unp_comments` WHERE newsid='$newsid'"); if ($DB->num_rows($getcomments) > 0) { while ($comments = $DB->fetch_array($getcomments)) { // grab and fix up comments $c_id = $comments['id']; $c_title = htmlspecialchars(stripslashes($comments['title'])); $c_name = htmlspecialchars(stripslashes($comments['name'])); $c_email = htmlspecialchars(stripslashes($comments['email'])); $c_date = unp_date($dateformat, $comments['date']); $c_time = unp_date($timeformat, $comments['date']); $c_text = nl2br(htmlspecialchars(stripslashes($comments['comments']))); $c_ipaddress = $comments['ipaddress']; $c_proxy = $comments['proxy']; $c_text = $n->unp_doSmilies($c_text); eval('$comments_list_commentbit = "'.unp_printTemplate('comments_list_commentbit').'";'); } } else { $comments_list_commentbit = ''; } } unset($news); } ?>
|
# ? Mar 26, 2008 01:14 |
|
Here's a time saving tip that can obviously be applied anywhere, but I first started using it with PHP's website. If you use Firefox then navigate over to php.net, right click on the search box and add a keyword of 'php' to the search. Now whenever you need to look up a function hit Ctrl+L (or otherwise get the focus on the address bar), type 'php <<function name>>' and there you are. It also works great if you don't remember the exact name but can come close, which is how I found imagecreatefromjpeg() from createfromjpeg().
|
# ? Mar 26, 2008 02:39 |
|
SmirkingJack posted:Here's a time saving tip that can obviously be applied anywhere, but I first started using it with PHP's website. If you use Firefox then navigate over to php.net, right click on the search box and add a keyword of 'php' to the search. Now whenever you need to look up a function hit Ctrl+L (or otherwise get the focus on the address bar), type 'php <<function name>>' and there you are. It also works great if you don't remember the exact name but can come close, which is how I found imagecreatefromjpeg() from createfromjpeg(). Another way to do it in Firefox is to go to Bookmarks > Organize bookmarks. Click 'New Bookmark', set the name you want, and paste the URL of a search query in there. replace the query words by '%s'. So 'http://ca3.php.net/manual-lookup.php?pattern=myfunction' --> 'http://ca3.php.net/manual-lookup.php?pattern=%s'. Then add the keyword you want to type in. The advantage is minimal, but in search engines like google you can specify the language (hl=en,fr, etc) or some other parameters that way. Opera works in a similar manner. Go to Tools > Preferences (ctrl+F12), press the 'search' tab. You can edit those that are there or enter new ones the same way firefox does (%s). Sorry for the derail.
|
# ? Mar 26, 2008 03:24 |
|
You can also just go to http://php.net/function_name to search for function_name.quote:Sorry, but the function function_name is not in the online manual. Perhaps you misspelled it, or it is a relatively new function that hasn't made it into the online documentation yet. The following are the 20 functions which seem to be closest in spelling to function_name (really good matches are in bold). Perhaps you were looking for one of these:
|
# ? Mar 26, 2008 04:35 |
|
Or download the php function look up extension for PHP here : http://www.folta.info/blog/
|
# ? Mar 26, 2008 21:25 |
|
I've recently taken up PHP as my language of choice for learning how to program. I now have a simple question regarding naming conventions in PHP. When a variable or function is declared with a single underscore as the first character (i.e. $_foo or $_fake_function()), what exactly does this tell me as a programmer?
|
# ? Mar 27, 2008 17:23 |
|
|
# ? May 16, 2024 17:31 |
|
Tap posted:When a variable or function is declared with a single underscore as the first character (i.e. $_foo or $_fake_function()), what exactly does this tell me as a programmer?
|
# ? Mar 27, 2008 17:32 |