|
|
#25 | |
|
Registered User
Join Date: Mar 2004
Posts: 15,486
|
Quote:
i typically use double quotes and escape them when i want them in the HTML. but single quotes would probably be a better idea. |
|
|
|
|
|
|
#26 | |
|
Ngemu Mod
Join Date: Jul 2003
Location: Fresno, CA
Posts: 1,886
|
Quote:
Code:
$var = 'text'; echo "<input type='$var' />"; The primary issue with using either single or double quotes with HTML within a string is when it comes to javascript function calls and their arguments when the arguments are javascript strings. In which case, either concatenation or quote escapes will work.
__________________
[i7 2600k @4.4ghertz][2x4 GB DDR3 1600][EVGA GTX570 1.280GB SC][EVGA GTX460 physx][Asrock Extreme7 Gen3 Z68][2xSeagate 160 Gb SATA HD raid0][Seagate 250 GB SATA2 HD][Sony Bravia 40' 1080p LCD HDTV][NEC 3520a DVD+-DLw][Windows 7 Ultimate x64][Rosewill 1000w] |
|
|
|
|
|
|
#27 |
|
Meow Mix Kills
Join Date: Aug 2002
Location: END OF DAYS
Posts: 1,228
|
I say a full OOP thread is the best, the sooner people get comfortable with it the sooner they will be better PHP programmers. You can hack up PHP code, but once you step into OOP as well as object model development you can really do some cool things that will make your life down the road 20x easier.
![]()
__________________
Gaming 5.0 Asus R4 Extreme | Core i7 3930K @ 4.8Ghz Corsair H100 | 16GB G.Skill@1866Mhz | 2xEVGA GTX 580 | Sammy 40" LCD Asus Essence One | OCZ Revo 3 120GB, Revo 3 X2 240GB | HSPC Tech Station | Corsair HX1200 | Windows 7 x64 Storage 2.0 Gigabyte Z68XP-UD3-iSSD | Core i7 2600K @ 4.5Ghz NH-D14 | 16GB G.Skill@1600Mhz | Areca 1880ix-16 RAID HBA Temp Storage - 1.8TB (4x450GB Hitachi 15k RPM SAS) | 18TB (12x3TB Hitachi RAID10) | HSPC Tech Station | Corsair HX620 | Windows 7 x64 |
|
|
|
|
|
#28 | |
|
Dethklok Returns!
|
OOP was a struggle for me at first because my first programming expereinces came with GWBASIC when i was in my early teens, so procedural programming didn't come to me as second nature. The only reason i knew about it was browsing php.net and stumbled upon "class". I read about it and thought to myself "this is cool! how the hell do i use it?!"
I looked at a couple tutorials and was having a hard time grasping it until I found one specific article about it and I eventually figured it out and spending an entire day making my own from scratch... So essentially, beyond that little tutorial I found, ive been learning on the fly. Even now, I'm just hoping I'm doing it right. Heres a template class I've been working on and off for a short while.... Any logical flaws in this way of implementing classes? Code:
class coreTpl extends coreDb {
public $tpl;
public $tpl_name;
public $tpl_fdir;
public $tpl_rdir;
public $tpl_ftpl;
public $tpl_fcss;
public $tpl_prts;
public function getTemplate ($name, $path) {
$s = 'SELECT * FROM `tpl` WHERE `name` = "'.$name.'" LIMIT 1'; // Get Template Info
$q = mysqli_query ($this->db, $s);
$r = mysqli_fetch_assoc ($q);
$this->tpl_name = $r['name'];
$this->tpl_fdir = $path.$r['dir'];
$this->tpl_rdir = $path;
$this->tpl_ftpl = $r['tpl'];
$this->tpl_fcss = $r['css'];
$this->tpl = file_get_contents ($this->tpl_fdir.$this->tpl_ftpl);
$this->tpl = coreTpl::rplPathStr ($this->tpl, $this->tpl_fdir);
}
public function inConStd ($loc, $name, $style, $sortBy, $SortType, $offset, $limit, $where) { // Grab Dynamic Content, And Insert Into Template
// Based on Loc
$conD = coreTpl::inConStyle($style); // Get Content Style HTML
$out = '';
$s = 'SELECT * FROM `con` WHERE `name` = "'.$name.'" ORDER BY `'.$sortBy.'` '.$SortType.' LIMIT '.$offset.', '.$limit;
$q = mysqli_query ($this->db, $s) or die (mysqli_error ($this->db));
while ($r = mysqli_fetch_assoc($q)) { // <-- Outer Loop: Take Row And Append HTML Data Then Content
$out .= $conD['top']; // Ex: TOP { Style0 | Part0 | Style1 | Part1 } BOTTOM
for ($x = 0; $x < $conD['parts']; $x++) { // <-- Inner Loop: Loop through array until Style Parts Meets Up With
$part = 'part'.$x; // Content Parts
$out .= $conD[$part]; // <-- Append HTML Before Content Text
$out .= $r[$part]; // <-- Append Content Text
}
$out .= $conD['bottom']; // <-- Append Bottom HTML After Last Part Is Appended
}
/* Out is the dynamic content and its associated style HTML, which will be inserted into the template where $loc specifies. The output will look
something like this:
Style TOP { Style Part0 | Content Part0 | Style Part1 | Content Part1 | Style Part2 | Content Part2 } Style BOTTOM
Style Can be any HTML, like a table, div, or just about anything else and is considered a text wrapper with all the styling HTML whereas the
content text is the actual dynamic text, which can be HTML as well. The number of parts is actually determined in the styling table. The inner loop
will stop at the last part based on that number. So if parts >> parts is 7 then it will loop 7 times through the content data like part0 to part6
columns in the associative array. An example could be something like this.
Parts = 3
Style = 'My Style'
Top = <table><tr>
part0 = <td>
part1 = </td><td>
part2 = </td></tr><tr><td colspan="2">
Bottom = </td></tr></table>
Content = 'My Example'
Part0 = FOO
Part1 = BAR
Part2 = BAZ
Call The Method As Specified $tpl->inConStd ('<!-- PLACEHOLDER -->', 'My Example', 'My Style', 'date', 'DESC', 0, 1);
And the Result Will Be:
<table><tr><td>FOO</td><td>BAR</td></tr><tr><td colspan="2">BAZ</td></tr></table>
This is just a simple example, calling this method based on your criteria will retrieve 1 or more records and will loop through all rows
returned form the query. You can also use whatever content you want with whatever style you want as well. You can also mix and match content
in whatever way you choose. For example, if you choose to implement the user the ability to use his/her own template style and color scheme or whatever,
it can be done very easily. Implement a little AJAX, and the user can do play with the content and page theme on the fly. Another reason is that you can
easily throw in as much content as you want, anywhere you want, and filter it in any way shape or form. In any case, with the content iteration methods
the site layout, content, and functionality is completely freeform. One last example, if you want to throw in a quick snippet of info form another page
that would normally not be on the site homepage, like a new users profile and all the features associated with profile accessability; and maybe put that
just above the main content because this new user is important.
*/
$out = coreTpl::rplPathStr ($out, $this->tpl_fdir); // Replace {{PATH}} and {{LIBPATH}} strings to relative locale
switch ($where) { // Insert Content Into Template where specified in $loc
case 'before':
$this->tpl = str_replace($loc, $out.$loc, $this->tpl);
break;
case 'after':
$this->tpl = str_replace($loc, $loc.$out, $this->tpl);
break;
default:
$this->tpl = str_replace($loc, $out.$loc, $this->tpl);
break;
}
}
private function inConStyle ($name) { // Get The Content Style Code
$s = 'SELECT * FROM `parts` WHERE `name` = "'.$name.'" LIMIT 1';
$q = mysqli_query($this->db, $s) or die(mysql_error());
$r = mysqli_fetch_assoc($q);
return $r;
}
private function rplPathStr ($str, $path) { // Replace Strings To Avoid Directory Confustion (WORKS)
$str = str_replace('{{LIBPATH}}', $this->tpl_rdir, $str); // Will replace {{LIBPATH}} in Template with Current Relative File Path
$str = str_replace('{{PATH}}', $path, $str); // Will replace {{PATH}} in Template with Current Relative File Path
return $str;
}
public function putHtml ($id, $src) {
}
}
Code:
class coreUsr extends coreDb {
public $usr_name;
public $usr_passwd;
public $usr_sid;
public $usr_auth;
public $usr_lvl;
public $usr_perm;
public function usrChkAuth ($name, $passwd) {
$s = 'SELECT * FROM `usr` WHERE `name` = "'.$name.'" LIMIT 1';
$q = mysqli_query($this->db, $s) or die(mysqli_error($this->db));
$r = mysqli_fetch_assoc($q);
if ($name == $r['name']) {
$userName = true;
} else {
$userName = false;
}
if ($passwd == $r['passwd']) {
$userPass = true;
} else {
$userPass = false;
}
if ($userName && $userPass) {
$this->usr_auth = true;
$this->usr_name = $r['name'];
$this->usr_passwd = $passwd;
$this->usr_lvl = $r['lvl'];
$this->usr_sid = session_id();
$this->usr_perm['addcon'] = $r['addcon'];
$this->usr_perm['updcon'] = $r['updcon'];
$this->usr_perm['delcon'] = $r['delcon'];
return true;
} else {
$this->usr_auth = false;
return false;
}
}
public function usrLogin () {
}
}
.... And as far as using what type of quotes, I always use single quotes and concatenation. I find it easier to proofread that way, and there is much less concern with escaping any strings, since theres a lot more double quotes going inside a string than single quotes. |
|
|
|
|
|
|
#29 |
|
Ngemu Mod
Join Date: Jul 2003
Location: Fresno, CA
Posts: 1,886
|
Your object definitions don't have a class constructor. Most OOP languages use constructors to initialize object variables. PHP is far more lenient in this regard and allows variables to be created on the whim without initialization. It does throw a bunch of warnings though.
A discussion about classes and objects also needs to touch on passing variables by reference and by value. PHP by default, makes all variables passed into functions by reference. There is a value in the php.ini to change it to pass by value. You can then pass by reference only when you explicitly do so. Ie. Code:
function passbyreference(&$str, &$obj, Array &$arr){
// do something
}
__________________
[i7 2600k @4.4ghertz][2x4 GB DDR3 1600][EVGA GTX570 1.280GB SC][EVGA GTX460 physx][Asrock Extreme7 Gen3 Z68][2xSeagate 160 Gb SATA HD raid0][Seagate 250 GB SATA2 HD][Sony Bravia 40' 1080p LCD HDTV][NEC 3520a DVD+-DLw][Windows 7 Ultimate x64][Rosewill 1000w] |
|
|
|
|
|
#30 | |
|
Mahna Mahna
Join Date: Jul 2006
Location: Madison, Wi
Posts: 6,123
|
I'm currently taking a PHP and MySQL class so, if anyone that's wanting to learn PHP and MySQL is interested I'd be happy to post our labs and projects from class here.
Just let me know and I'll get to it.
__________________
|
|
|
|
|
|
|
#31 | |
|
plenty of work, no games
Join Date: Sep 2007
Posts: 559
|
Quote:
Well, difference between single and double quotes is that double quotes get parsed, while single quotes do not. Ie. that if you do not need PHP to parse your strings, you should NOT use double quotes. You should also not use [dot] to concat strings, much faster is to use comma, as it does not concat them, but just echoes them. So, this is fastest: echo '1', $itemid; This is slower: echo "1$itemid"; And this would be slowest: echo "1".$itemid; All those examples produce same result, of course.
__________________
Q9550@3.4 + Asus P5Q Premium + 16GB RAM + 2xVelociraptor 300GB + 4xWD Black 1TB RAID-5 on Adaptec 5805 + PoV GTX580 + Dell 3008WFP + Windows 7 x64 Xbox 360 Elite + Kinect + Onkyo receiver + Acoustic Energy Aelite 1/3/center speakers + 46" FullHD Samsung TV |
|
|
|
|
|
|
#32 | |
|
Registered User
Join Date: Jan 2005
Location: Rochester, MN
Posts: 4,018
|
Quote:
). Also, it doesn't apply to the example because the result of the concatenation is being assigned to a variable, not echo'd.So I guess my point is that it's a useful tip, but your statement that "You should also not use [dot] to concat strings" is not correct without qualification. |
|
|
|
|
|
|
#33 | |
|
plenty of work, no games
Join Date: Sep 2007
Posts: 559
|
Quote:
Like "You should also not use [dot] to concat strings unless you really need it"What is important: - content of "" gets parsed - content of '' does not
__________________
Q9550@3.4 + Asus P5Q Premium + 16GB RAM + 2xVelociraptor 300GB + 4xWD Black 1TB RAID-5 on Adaptec 5805 + PoV GTX580 + Dell 3008WFP + Windows 7 x64 Xbox 360 Elite + Kinect + Onkyo receiver + Acoustic Energy Aelite 1/3/center speakers + 46" FullHD Samsung TV |
|
|
|
|
|
|
#34 | |
|
Registered User
Join Date: Jan 2005
Location: Rochester, MN
Posts: 4,018
|
Quote:
![]() |
|
|
|
|
|
|
#35 |
|
Registered User
Join Date: Mar 2004
Posts: 15,486
|
im sorry i have been tremendously busy with school. i will get to the tutorial asap.
![]() |
|
|
|
|
|
#36 |
|
|
|
|
|
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Official Max Payne 3 Feedback Thread | Ghosthunter | Gaming Central | 94 | 10-05-12 06:00 AM |
| Detonator 40.72 feedback thread | mongoose | NVIDIA Windows Graphics Drivers | 94 | 12-03-02 10:45 AM |
| Official detonator 40.71 feedback thread | Crake | NVIDIA Windows Graphics Drivers | 88 | 10-01-02 11:38 AM |
| Detonator 30.30 feedback thread | Matthyahuw | NVIDIA Windows Graphics Drivers | 26 | 07-31-02 09:14 PM |