|
argz posted:what? When I'm scanning a 5000 line file, it's easy to just search for the word 'echo'. It catches the eye better than an equals sign.
|
# ? Aug 29, 2009 02:14 |
|
|
# ? Jun 6, 2024 08:22 |
|
argz posted:what? gibbed fucked around with this message at 04:07 on Aug 29, 2009 |
# ? Aug 29, 2009 04:03 |
|
scrabbleship posted:It might but it is probably a bit overkill for what my client wants. This would probably overwhelm him. He just wants something he can see the entries in the table with and modify/delete faulty ones with; nothing to fancy. Thanks for the suggestion nonetheless. http://stefangabos.blogspot.com/search/label/Data%20Grid%20PHP%20Class%20Description/
|
# ? Aug 29, 2009 04:39 |
|
Does anyone know, if it is required to compile php with --debug-enabled in order to be able to use the full functionality of xdebug? The reason why I am asking: We have strange issues, that occur only on our live system and not on our development/test system. Our live system has php debug disabled for performance reasons. And I would like to know this, before I start messing with/installing xdebug on it.
|
# ? Aug 29, 2009 14:44 |
|
gibbed posted:Short tag is <?, not <?=, and <?= is magic for <? echo. Is <?= not included in this argument? quote:Note: This directive also affects the shorthand <?= , which is identical to <? echo . Use of this shortcut requires short_open_tag to be on.
|
# ? Aug 30, 2009 02:06 |
|
argz posted:Is <?= not included in this argument? Exactly. Nobody really cares about <?, but <?= is a really neat shortcut that would make templates look just that little bit nicer.
|
# ? Aug 30, 2009 10:26 |
|
haywire posted:Exactly. Nobody really cares about <?, but <?= is a really neat shortcut that would make templates look just that little bit nicer. Simple matter of benefits outweighing the cost. Would I rather type an XML file fix once for the times where I use XML or every time I'm adding a variable? The obvious thing here is the latter uses far more characters and gets messier quicker. I think this is a poor excuse to remove the short tags.
|
# ? Aug 30, 2009 17:12 |
|
Thibaw posted:Does anyone know, if it is required to compile php with --debug-enabled in order to be able to use the full functionality of xdebug?
|
# ? Aug 30, 2009 21:34 |
|
argz posted:Simple matter of benefits outweighing the cost. Would I rather type an XML file fix once for the times where I use XML or every time I'm adding a variable? Either way, they should make the disabling of <? and <?= seperate, and <?= should be enabled by default. What possibly argument is there against that?
|
# ? Aug 31, 2009 02:56 |
|
I'm needing some help with pre_replace I'm extracting <a> tags from source codes, and basically want to strip out all non-href parts. I've already got the script to return to me only <a> tags... but if the tag has a "class" or any other thing inside, it'll mess it up, so what I want to do is: if $value has text that != 'href="$s"' or 'href=$s', remove that unnecessary text. I've already taken into account "target=" by simply running a str_replace Any help on this would be returned with eternal love! edit: got it: http://semlabs.co.uk/journal/php-strip-attributes-class-for-xml-and-html Best class ever! eHacked fucked around with this message at 17:45 on Aug 31, 2009 |
# ? Aug 31, 2009 16:49 |
|
Help? I have an issue wherein I want to include a file if a variable from the page is not blank but to not show it if the variable is blank. Here's how (in my stupid head) it should be - I'm not quite php enough to figure out how to do this though. Anyone want to school me on the proper way to write this? code:
|
# ? Sep 2, 2009 12:42 |
|
pipebomb posted:Help? Hmm, you said if not blank in the top, but then wrote the pseudo code like if it is blank, just switch out the comparison operator if you want otherwise >> == vs. != code:
|
# ? Sep 2, 2009 13:02 |
|
You are a beautiful soul and I love you. Sorry about the error, glad you caught it...this works perfectly, thank you!argz posted:Hmm, you said if not blank in the top, but then wrote the pseudo code like if it is blank, just switch out the comparison operator if you want otherwise >> == vs. !=
|
# ? Sep 2, 2009 13:34 |
|
My 2 cents on the issue...pipebomb posted:Help? 1. Use brackets, you'll save yourself a giant headache 2. Use single quotes for single characters, use double quotes for multiple characters 3. Don't use "if-then", brackets take care of that (see rule 1) 4. Comparison has to be "==", not the single "=". Single equals sign isn't a comparison, you're setting $data to be a blank string. But since you want it to include the file if it's NOT blank, it has to be "!=" php:<? if($data != '') {include("share.php");} else {echo("<br />");} ?>
|
# ? Sep 2, 2009 19:13 |
|
Mr Viper posted:My 2 cents on the issue... All good points, with the minor addendum that single quotes are for when you don't want the string processed for variables and special characters (like \n for newlines). Double quotes are for when you do want that processing. They are not interchangeable on a whim. php:<? $world = 'KuruMonkey'; // used single quotes; no variables etc in this string echo 'hello, $world<br>'; echo "hello, $world<br>"; echo 'you see?'; ?> code:
Single quotes are, because of that lack of processing, marginally more efficient than double quotes. In a complex string managing program, it can add up. (its a habit to build; singles where no variables, doubles where variables) Edit: the real pro-tip is, of course, to be consistent in your style. Thats always more important than exactly what your style is. Which was the main thrust of the previous reply, I think. KuruMonkey fucked around with this message at 19:41 on Sep 2, 2009 |
# ? Sep 2, 2009 19:39 |
|
Oh yeah, that's true about the single/double quotes thing. I just never use variables in the middle of strings, I've never felt comfortable doing it. I'll just typecode:
|
# ? Sep 2, 2009 19:49 |
|
Mr Viper posted:Oh yeah, that's true about the single/double quotes thing. I just never use variables in the middle of strings, I've never felt comfortable doing it. I'll just type I do that, too. I agree it's cleaner and it's easier to pick out variables in strings when you're scanning through code (in my opinion at least). I never knew this thread (and the web dev thread) existed. It makes me happy that there is at least one thread on SA that I might actually be able to helpfully contribute to.
|
# ? Sep 2, 2009 21:06 |
|
Mr Viper posted:Oh yeah, that's true about the single/double quotes thing. I just never use variables in the middle of strings, I've never felt comfortable doing it. I'll just type It's better to put the variable in curly braces if you're putting them in quotes, plus it lets you use non-alphanumeric characters, like -> and []. Your IDE had better highlight it as well. php:<? echo "hello my name is {$person->name}!";?>
|
# ? Sep 2, 2009 21:31 |
|
xezton posted:I do that, too. I agree it's cleaner and it's easier to pick out variables in strings when you're scanning through code (in my opinion at least). I'm so very, very ashamed... php:<? foreach(array('Type','Null','Key','Default','Extra') as $v){ if(${"c$v"}!=${"n$v"}){ echo("***\t ojs222.$table.$cField $v '".${"c$v"}."' => ojs.$table.$nField $v '".${"n$v"}."'\n"); switch($v){ ... } } } ?>
|
# ? Sep 2, 2009 21:43 |
|
duz posted:It's better to put the variable in curly braces if you're putting them in quotes, plus it lets you use non-alphanumeric characters, like -> and []. Your IDE had better highlight it as well. php:<? "$someObject->someLocal" //works in my test "$someArray[1]" //works fine, too (maybe just in 5+?) ?>
|
# ? Sep 2, 2009 22:05 |
|
duz posted:It's better to put the variable in curly braces if you're putting them in quotes, plus it lets you use non-alphanumeric characters, like -> and []. Your IDE had better highlight it as well. Wait, from a speed perspect isn't "blah".$blah the fastest? With "blah $blah" php has to iterate through the string to find all the variables :S For I rather like printf/sprintf, though Ideally you shouldn't echo except within a template, though. I personally find concatenation to be easiest to read, too. "Blah blah blah" . $ohlookavariable . "blah";
|
# ? Sep 2, 2009 22:42 |
|
haywire posted:Ideally you shouldn't echo except within a template, though. Hold on, what? What do you mean?
|
# ? Sep 2, 2009 22:45 |
|
Mr Viper posted:Hold on, what? What do you mean? Surely you should only output once you have decided what your output is (IE after system logic). Rat Supremacy fucked around with this message at 22:54 on Sep 2, 2009 |
# ? Sep 2, 2009 22:49 |
|
haywire posted:
I prefer to fully write out my code rather than do the quick shortcuts, it's just so much easier for me. Not that I have a problem with the superfast haxxor scripting, and it's not like the pages go slow or anything, I just do it my way. Three spaces per tab, brackets organized all nice and clean, no 200 character lines of a huge function. So, not to repeat myself, but what?
|
# ? Sep 2, 2009 22:52 |
|
quote:
What are you actually asking me? IIRC what I'm talking about is more laid out and has more code. :S Having dynamic data in data sent to a template for output. Also, what I suggested earlier works, but not for echo, weirdly. php:<?php strlen( $data ) > 0 ? printf( "<br/>" ) : include( "a file" ); ?> Edit: Oh wait, did you think I was trying to say that not using whitespace when concatenating was faster? Obviously that isn't true, they're interchangable. Rat Supremacy fucked around with this message at 13:07 on Sep 12, 2009 |
# ? Sep 2, 2009 22:56 |
|
haywire posted:Also, what I suggested earlier works, but not for echo, weirdly. That's not so weird - echo is one of those magical things that doesn't work outside the narrow context some PHP dev felt it should be used in (like empty) quote:Surely you should only output once you have decided what your output is (IE after system logic). Heh, sounds like someone works with a codebase that's actually organized according to some well-known development scheme other than "write C in PHP and what the gently caress is a 'standard,' anyway?"
|
# ? Sep 2, 2009 23:08 |
|
Munkeymon posted:
Must've fixed that in 5.something then because I could've sworn it didn't used to work. Curly braces are still good for the variable variable name trick though. haywire posted:Wait, from a speed perspect isn't "blah".$blah the fastest? With "blah $blah" php has to iterate through the string to find all the variables :S No idea about the speed vs concat or inline, if you're using " it will be evaluating regardless. None of my code has gotten to the point where that would make a difference so I havn't checked. Mr Viper posted:Hold on, what? What do you mean? He means you shouldn't be outputting anything until you're done processing all your data. Assuming you're using some type of MVC setup or something similar.
|
# ? Sep 2, 2009 23:13 |
|
Is there a good reason to use sprintf instead of str_replace? Is it faster?
|
# ? Sep 2, 2009 23:25 |
|
Hammerite posted:Is there a good reason to use sprintf instead of str_replace? Is it faster? You use them for very different things in general, so it's not really an "instead" thing. EDIT: as for the discussion du jour, I used to be an echo guy, but I have come to love the printf Lumpy fucked around with this message at 23:58 on Sep 2, 2009 |
# ? Sep 2, 2009 23:56 |
|
Lumpy posted:You use them for very different things in general, so it's not really an "instead" thing.
|
# ? Sep 3, 2009 00:32 |
|
Lumpy posted:You use them for very different things in general, so it's not really an "instead" thing. Well... I am in the middle of internationalising my site, and I have various pieces of text that I'm allowing users to translate into other languages so that my pages can be in multiple languages. The way I do this is to have a database table of english phrases; one column in this table records which page a phrase is used from, so at the start of a script I load all the phrases for that page and put them in an array, $TranslatableText. Then if the user has his language set to something other than English, I fetch corresponding translations, and translations that exist overwrite the English versions of text in $TranslatableText. I have the following function: php:<? function transtext($x) { global $TranslatableText; if ( isset($TranslatableText[$x]) ) { return $TranslatableText[$x]; } else { return 'MISSING TEXT ('.$x.')'; } } ?> php:<? echo str_replace( array('\start','\end','\playername'), array($LocationNames[$RailStarts[$i]], $LocationNames[$RailEnds[$i]], $RailOwners[$i] ), transtext(193) ); ?>
|
# ? Sep 3, 2009 00:39 |
|
Never mind - I did my own test and found that for a typical string I want processed in this way, str_replace takes about 50% longer than sprintf. I guess I'm not sure whether that's worth getting worked up about, when using str_replace leads to more readable code and to translation work that's easier to review and understand.
|
# ? Sep 3, 2009 02:23 |
|
duz posted:Must've fixed that in 5.something then because I could've sworn it didn't used to work. Curly braces are still good for the variable variable name trick though. You'd think so. Funnily enough, it "blah" . $blah is faster than 'blah' . $blah, with "blah $blah" being the slowest. Yes, this scared me too. TBH speed isn't really a factor, but variables in strings is just one of those horrible things that makes PHP horrible. quote:
Yeah, this is ideal. Even if you arent you can have a buffer for $output, as it helps you to be organised. waffle iron posted:I'm a real big fan of printf and sprintf and vsprintf. The formatting abilities make it easier to read. Also useful if you end up having to do localization later. It is so nice. If your language file can contain things like "welcome back, %s", your life is so much easier. It is one of the main reasons I discovered sprintf other than previous use of C.
|
# ? Sep 3, 2009 10:34 |
|
duz posted:Must've fixed that in 5.something then because I could've sworn it didn't used to work. Curly braces are still good for the variable variable name trick though. This is 5.2.5, which is closing in on its second birthday, but I gather being on the bleeding edge of PHP isn't something most server admins are really concerned with.
|
# ? Sep 3, 2009 14:34 |
|
I'm having some problems with the output buffer. I am buffering my script and printing the result using a callback. The problem is that if a error is thrown at any point, nothing is being shown and I am getting a blank screen. I have tried setting my own custom error handlers but nothing seems to work. I have a feeling this is because the errors are causing my buffer to call the callback method instead of flushing in my error handler. Either that or it's because I have the error handler as a static method, but changing this causes issues. I'd really appreciate any help because this one has me stumped! code:
|
# ? Sep 5, 2009 00:40 |
|
Hanpan posted:set_exception_handler(array(_C_LASS__, 'exception_handler')); Typo in your post, or typo in your file? Edit: Sorry, not even sure anymore what the hell I was thinking. Yes you can check error_reporting (it returns an int of the last value it was set to), but not sure what benefit I thought that would provide. Maybe I meant error_get_last(). Damned if I know for sure, sorry. Supervillin fucked around with this message at 23:03 on Sep 6, 2009 |
# ? Sep 5, 2009 03:08 |
|
Supervillin posted:Typo in your post, or typo in your file? Sorry, typo in my post. It's all fine in the script. Could you elaborate on what you mean by "fetch the result"? I thought error_reporting() was just a way of changing which errors are shown?
|
# ? Sep 5, 2009 11:33 |
|
The Codeigniter thread is apparently closed, but I'm trying to get going with Codeigniter now and running in to a big problem. I seem to have error logging and the display of errors turned on (it's the default setting), but I can't figure out what the gently caress is wrong with the Database library. As soon as I try to call it (either from autoload or explicitly) I get just a blank page instead of all the content that should be there....like the error message. I'm pretty drat sure I'm feeding the database library the right server info, but it refuses to start and won't tell me why. The question is: how do I get access to the error message? I can't fix it if I don't know what's wrong. edit: I have it working on my paid-for web server, but not my local machine. MySQL itself, PHP, and Apache are all otherwise working very well on my local machines. On the hosted site it will throw an error and on my local machines it will only die and give me a blank page. What's up here? edit2: I meant to say it's working just fine with the correct settings on the remote web server. It will also throw an error with the incorrect settings. Locally, all I get is a blank page with correct or incorrect settings. FIXED! After nearly a day of searching to fix this problem I finally found a post that narrowed it down for me: re-install PHP and include the MySQL module - which I thought was enabled by default. Oh well. TreFitty fucked around with this message at 07:07 on Sep 6, 2009 |
# ? Sep 6, 2009 03:40 |
|
I am extremely new to PHP and don't know where to begin with this, but it seems simple enough. I want to dynamically generate a list of links from a database. So for example I would have some sort of database or file on my website that was just a single column on numbers: 125375 193745 058214 Like that and it would insert the numbers into two links: 1. site.com/link?id=125375 site.com/link2?id=125375 2. site.com/link?id=193745 site.com/link2?id=193745 3. site.com/link?id=058214 site.com/link2?id=058214 Also, I want to format the output into an ordered list. I don't really know what I am doing, so any help is appreciated. Thanks. Happysafer fucked around with this message at 15:18 on Sep 7, 2009 |
# ? Sep 7, 2009 14:02 |
|
|
# ? Jun 6, 2024 08:22 |
|
Happysafer posted:I am extremely new to PHP and don't know where to begin with this, but it seems simple enough. I want to dynamically generate a list of links from a database. So for example I would have some sort of database or file on my website that was just a single column on numbers: How you get the list of numbers in the first place will vary depending on whether you are using a database management system (DBMS), storing the data in a text file, or using some other method to store it (you don't seem sure). If you're storing it in a file then PHP has input/output functions that you can use to get at it. I'm not familiar with these. If you're using a database, then the functions used to connect to the database and issue queries depends on which DBMS you are using, but the query itself will be the same regardless of the DBMS, as it's quite a simple thing you want to do. Here is how I would do what you are describing, using a MySQL database called MyDatabase with a table called MyTable in which is the single column MyColumn. (Since you give an example of a number with leading zeroes, I guess you might use a CHAR or VARCHAR datatype for the column. They all seem to be the same number of digits though, and if that's always the case you could make the column an integer type and give it the ZEROFILL attribute. Whichever you did, the ORDER BY clause given here would work.) php:<? $host = 'localhost'; $user = 'username'; // Enter the name of your database user here $password = 'password'; // Enter the password for that database user here $dbname = 'MyDatabase'; $dblink = @mysqli_connect($host,$user,$password,$dbname) or die('Failed to connect to database'); $query_result = mysqli_query($dblink,'SELECT MyColumn FROM MyTable ORDER BY MyColumn') or die('Failed to read database table'); $output = ''; $i = 0; while ( $number = mysqli_fetch_assoc($query_result) ) { $i++; // The line number needs to get bigger every time $output .= $i. // Puts in the line number '. site.com/link?id='. $number['MyColumn']. ' site.com/link2?id='. $number['MyColumn']. '<br>'; // Adds an HTML line break at the end } echo $output; // Echoes the output to your browser ?> Hammerite fucked around with this message at 18:32 on Sep 7, 2009 |
# ? Sep 7, 2009 18:28 |