Daniel0
Staff Alumni-
Posts
11,885 -
Joined
-
Last visited
Everything posted by Daniel0
-
[SOLVED] need advice on learning php please , php is my dream goal
Daniel0 replied to silverglade's topic in Miscellaneous
Aim on being a great overall programmer, not a great PHP programmer. PHP is a tool, a means to the goal, but not the goal itself Learning PHP specifically is not so important. That is just syntax and knowing some useful library functions. What is far more important is methodology, troubleshooting/debugging skills and problem solving skills. When you are coding you're solving a problem. You may have very complex problems or easy problems. What you need to learn is how to break the complex problems into smaller and easier problems that you already know how to solve. -
PHP is a language with many possibilities (including global and goto) and what's a curse for one may be a blessing for another. Provide an example then.
-
Yeah, it's basic statistics. The law of large numbers, and such. Because 1 is the largest digit in binary, 1 must be a large number. Clearly one observation is a good enough data set to conclude something about the population.
-
There exists no good free forum software that I know of, so you have to take what you can get unless you have time to roll your own.
-
Then use urlencode.
-
Well, it's not like it would be particularly difficult creating a script that auto-generates it.
-
API-wise there is no difference between a function you wrote, PHP's built-in functions, functions provided by PECL extensions, etc. The only difference is how and where they are implemented. When calling a function, PHP doesn't really care where it comes from. That would not be an object oriented approach though. OOP deals with objects, their behavior, state and interaction with each other. It's in no way about grouping similar or related functions together. The latter would still be procedural programming.
-
Try using <?php instead of <?. Short tags are disabled by default in PHP5.
-
Really? So when writing object oriented code in PHP5 you never use library functions provided by PHP? That's quite an amazing feat considering the way PHP is designed as a language. Also, OOP is not specifically for PHP5 and procedural for PHP4. You can easily write procedural code in PHP5 as well. If you are aiming for as pure OOP as possible you wouldn't mix these, but it certainly is possible. Because I favor OOP I wouldn't do that, however. Nor would I like to take over such a project. By the way, you don't call the things in objects for functions, but rather methods. Just a minor note on the nomenclature
-
A class and a function is not the same.
-
Seems okay, except you should just place the files you don't want people to access outside of the document root.
-
You know, there is this nifty function called count that counts the number of elements in an array (or an object implementing the Countable interface). Now, who would have thought that? Of course there is no default total.
-
That's difficult to say. If you're using Firefox I'd recommend you to install Firebug and experiment with its "Inspect Element" feature.
-
The book is called Discrete Mathematical Structures by Kolman, Busby and Ross, but that's beside the point. My point was that you figure out the number of pages by counting the number of items. You then just divide by the number of items you want per page and ceil that number.
-
This is the first sentence in the chapter on counting in my discrete mathematics book: Now I'll guess what you're supposed to do in order to figure out how many pages there are.
-
Yeah, that's a known "bug" in SMF. Technically speaking it isn't a bug though. It's because [0] is a bbcode representing a list item. One might of course argue that it shouldn't be interpreted as that without being inside tags.
-
That is not evidence it's because of Smarty. As I said previously, your old code probably sucked. If you had loading times of over 10 seconds, then I find that reasonably ostensible. Did you ever profile it to figure out where the bottleneck was?
-
It'll be like this: echo preg_replace('/http:\/\/www.mysite.com\/name\/(.*?)\//ie',"strtolower('\\1')",$str); The e modifier tells it that the thing in the second argument should be evaluated as PHP code.
-
Uh... just place that line somewhere along the end.
-
No, it's actually turned into this monstrous piece of code (that is the cached version): <?php /* Smarty version 2.6.26, created on 2009-08-22 12:59:29 compiled from mysqltable.tpl */ ?> <?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); smarty_core_load_plugins(array('plugins' => array(array('modifier', 'escape', 'mysqltable.tpl', 5, false),array('modifier', 'date_format', 'mysqltable.tpl', 7, false),)), $this); ?> <h1>PHP Freaks Tutorials</h1> <?php unset($this->_sections['tut']); $this->_sections['tut']['name'] = 'tut'; $this->_sections['tut']['loop'] = is_array($_loop=$this->_tpl_vars['tutorials']) ? count($_loop) : max(0, (int)$_loop); unset($_loop); $this->_sections['tut']['show'] = true; $this->_sections['tut']['max'] = $this->_sections['tut']['loop']; $this->_sections['tut']['step'] = 1; $this->_sections['tut']['start'] = $this->_sections['tut']['step'] > 0 ? 0 : $this->_sections['tut']['loop']-1; if ($this->_sections['tut']['show']) { $this->_sections['tut']['total'] = $this->_sections['tut']['loop']; if ($this->_sections['tut']['total'] == 0) $this->_sections['tut']['show'] = false; } else $this->_sections['tut']['total'] = 0; if ($this->_sections['tut']['show']): for ($this->_sections['tut']['index'] = $this->_sections['tut']['start'], $this->_sections['tut']['iteration'] = 1; $this->_sections['tut']['iteration'] <= $this->_sections['tut']['total']; $this->_sections['tut']['index'] += $this->_sections['tut']['step'], $this->_sections['tut']['iteration']++): $this->_sections['tut']['rownum'] = $this->_sections['tut']['iteration']; $this->_sections['tut']['index_prev'] = $this->_sections['tut']['index'] - $this->_sections['tut']['step']; $this->_sections['tut']['index_next'] = $this->_sections['tut']['index'] + $this->_sections['tut']['step']; $this->_sections['tut']['first'] = ($this->_sections['tut']['iteration'] == 1); $this->_sections['tut']['last'] = ($this->_sections['tut']['iteration'] == $this->_sections['tut']['total']); ?> <div class="tutorial" id="tut-<?php echo $this->_tpl_vars['tutorials'][$this->_sections['tut']['index']]['content_id']; ?> "> <h2><?php echo ((is_array($_tmp=$this->_tpl_vars['tutorials'][$this->_sections['tut']['index']]['title'])) ? $this->_run_mod_handler('escape', true, $_tmp) : smarty_modifier_escape($_tmp)); ?> </h2> <small><?php echo ((is_array($_tmp=$this->_tpl_vars['tutorials'][$this->_sections['tut']['index']]['created_at'])) ? $this->_run_mod_handler('date_format', true, $_tmp, "%B %e, %Y, %H:%M") : smarty_modifier_date_format($_tmp, "%B %e, %Y, %H:%M")); ?> </small> <div class="summary"> <?php echo ((is_array($_tmp=$this->_tpl_vars['tutorials'][$this->_sections['tut']['index']]['summary'])) ? $this->_run_mod_handler('escape', true, $_tmp) : smarty_modifier_escape($_tmp)); ?> </div> <a href="http://www.phpfreaks.com/tutorial/<?php echo $this->_tpl_vars['tutorials'][$this->_sections['tut']['index']]['permalink']; ?> ">Read more</a> </div> <?php endfor; endif; ?> This is the code that is being run each time. There is no "magic" going on. The only thing compile_check does is that it checks if the template file has been modified. If you disable that then you disable the check. It can be used in a production environment because the template is unlikely to change very often there. Don't believe me? I dare you to read the manual. It'll be SUPA clear to you. Give it up or come up with some real arguments or evidence.
-
Checking to see if a string is only zen-kaku characters
Daniel0 replied to paullb's topic in PHP Coding Help
All the ranges are specified on unicode.org -
I suppose you on every page could do this: $_SESSION['last_request'] = $_SERVER['REQUEST_URI']; And then on the page you don't want refreshes on: if ($_SESSION['last_request'] == $_SERVER['REQUEST_URI']) { echo 'Refreshing is not allowed.'; } You'll want to update the last_request at the end of script execution though.
-
In that case, the isset() is redundant. !empty($something) == true implies isset($something) == true. Always.
-
Read my post... I said "suppose we have [...]". I didn't say that it was defined in your specific scenario. The variable $currentPage would obviously be a variable holding an integer value corresponding to whatever page the user is currently at.
-
No, it's much simpler. Suppose we have a variable $numPages and a variable $currentPage. To determine if we should show the "Next" link we'll do: if ($currentPage < $numPages) { // display next } Almost similarly with the "previous" link: if ($currentPage > 1) { // because 1 is the first page // show previous }