PHP - Spl_autoload_register And Class Upper/lower Case
I mostly if not always name my classes with the first letter capitalized.
I typically use enable autoloading as follows. I don't know when I started converting the class name to under-case. As such, however, I need to make the filenames undercase.
Is this the correct approach?
spl_autoload_register(function ($class) { $class=strtolower($class); if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.$class.'.php')) { require_once __DIR__.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.$class.'.php'; } }); Similar TutorialsHi, I wonder if some one could help me. I am trying to set up a few rules to make sure that users create safe passwords on my site: I have the below check which makes sure that the user enters a word of at least 8 charachters long: Code: [Select] if( strlen($password) < $MaxPwdLength ){ $errmsg_arr[] = 'Password must be at least 8 charachters long '; $errflag = true; } Does anyone know how I could write an if function to make sure that the ser is entereing a password with at least one capital and one lower case letter in. Hope you can help. Thanks Ed From what I understand we can use ucfirst to convert the first letter within a string to upper case. What I would like to know is if there is a function that exists that would convert the first letter of every paragraph to upper case. For example: From: Code: [Select] This is a paragraph. is this the car blue? let's go for a pint of beer! To: Code: [Select] This is a paragraph. Is this the car blue? Let's go for a pint of beer! Does any such function exist? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=327423.0 i want to make a simple forced lower case form but i got stuck on it
to begin with i want to everything user's write and submit convert to lowercase
am i using the right code? i'm not sure about using preg_match in this situation but i dont know what else to do don't be harsh with me i'm noob <?php if(isset($_GET['user'])&&!empty($_GET['user'])) { $user = $_GET['user']; if (preg_match('$englishUpperAlphabet'//English alphabet Upper case array//',$user)){ $user = mb_strtolower($user); echo $user; } else{ echo 'none'; }} ?> <form action="t.php" action="GET"> name: <input type="text" name="user" > <br> <input type="submit" value="submit" > </form> hi i have some questions about spl_autoload_register when the first param is null. eg. spl_autoload_register(null, false); the manul describe" If no parameter is provided, then the default implementation of spl_autoload() will be registered." now why the follow can't run <?php spl_autoload_register(NULL, false); spl_autoload_extensions('.class.php, .php'); $demo2 = new Demo2();//Demo2.class.php is exist ?> the fllow can run <?php spl_autoload_extensions('.class.php, .php'); spl_autoload('Demo2'); $demo2 = new Demo2(); ?> so , what's the meaning of spl_autoload_register(null, false)? anyone can give me some examples, thanks. Hi,
I've just found that __autoload function is no longer the thing to use when creating an object from your class. Well thanks a lot!!! Now we have this spl_autoload_register AND spl_autoload. All the manuals I've read I am still lost... just a simple example would be great!!!
Morning all, I'm trying to query a user table and am receiving errors. In the mysql statement I am trying to SELECT all data from the table that matches the username of the person logged in. The error I am receiving is this: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\123\myaccount.php The database query is written correctly, if I am logged in as the user Admin then I recieve this message as well: Unknown column 'Admin' in 'where clause' from the or die(mysql_error());. In the database the username is: admin but I can login using Admin, is this an issue of upper and lowercase? The PHP code is below: Code: [Select] <?php require_once('connect.php'); $query = mysql_query("SELECT * FROM user WHERE username = $_SESSION[gatekeeper]"); while ($row = mysql_fetch_array($query) or die(mysql_error())); { echo"<div class='BlockContent'>"; echo" <table id='UserList'>"; echo" <tr>"; echo" <th>My Account</th>"; echo" </tr>"; echo" <tr>"; echo" <td id='left'>"; echo" </td>"; echo" </tr>"; echo" </table>"; echo"</div>"; } ?> Is there any way to access a variable that is not assigned until further down the page eg: echo $myname; $myname = 'batman'; // clearly my real name which is why I am so poor at coding Thanks Hi, I am tryng to use the gd functions in php to output an image of a lower quality and save it as another image: Code: [Select] header('Content-Type: image/jpeg'); $im = @imagecreatefromjpeg('SDC10424.JPG'); imagejpeg($im, null, 50);// this line lowers the image quality imagedestroy($im); but the problem is how to save it? I tried file_put_contents, but it didnt work, like fileputcontents("test.jpg", $im); Hello, I've got what should be a simple solution here. I've tried many things but it just won't work for me. This is what I have. I've got a wysiwyg editor setup to write to a file called news.php. The file that has the editor is edit/index.php. It's just a simple textarea. The textarea is supposed to include news.php. For some reason, it won't let me include that file that is in a lower directory. The file that writes to news.php is called edit/write.php. edit/write.php doesn't write to news.php instead it writes to edit/news.php. The only reason I want to include the lower directory is so that I can put a .htaccess password protection on the edit directory. I'll include some code below. Code: (edit/index.php) [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> <head> <title>Editing News</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <script type="text/javascript" src="nicEdit.js"></script> <script type="text/javascript"> bkLib.onDomLoaded(function() { nicEditors.allTextAreas() }); </script> <form method="post" action="write.php"> <p> <textarea name="content" style="width:100%;height:1000px;"><?php include '../news.php';?></textarea> <input type="submit" value="Save" /> </p> </form> </body> </html> Code: (edit/write.php) [Select] <?php $File = "../news.php"; $Handle = fopen($File, 'w'); $Data = $_POST['content']; fwrite($Handle, $Data); fclose($Handle); header("Location: index.php"); ?> index.php is just a simple include news.php. Am I missing an easy step? Any help would be great!! Thanks! Im displaying scores from my database from highest to lowest but 10 always comes out first. Why? I have mysqli object in Database class base: [color=]database class:[/color] class Database { private $dbLink = null; public function __construct() { if (is_null($this->dbLink)) { // load db information to connect $init_array = parse_ini_file("../init.ini.inc", true); $this->dbLink = new mysqli($init_array['database']['host'], $init_array['database']['usr'], $init_array['database']['pwd'], $init_array['database']['db']); if (mysqli_connect_errno()) { $this->dbLink = null; } } } public function __destruct() { $this->dbLink->close(); } } Class derived is Articles where I use object dBLink in base (or parent) class and I can't access to mysqli methods (dbLink member of base class): Articles class: require_once ('./includes/db.inc'); class Articles extends Database{ private $id, .... .... $visible = null; public function __construct() { // Set date as 2009-07-08 07:35:00 $this->lastUpdDate = date('Y-m-d H:i:s'); $this->creationDate = date('Y-m-d H:i:s'); } // Setter .... .... // Getter .... .... public function getArticlesByPosition($numArticles) { if ($result = $this->dbLink->query('SELECT * FROM articles ORDER BY position LIMIT '.$numArticles)) { $i = 0; while ($ret = $result->fetch_array(MYSQLI_ASSOC)) { $arts[$i] = $ret; } $result->close(); return $arts; } } } In my front page php I use article class: include_once('./includes/articles.inc'); $articlesObj = new articles(); $articles = $articlesObj->getArticlesByPosition(1); var_dump($articles); [color=]Error that go out is follow[/color] Notice: Undefined property: Articles::$dbLink in articles.inc on line 89 Fatal error: Call to a member function query() on a non-object in articles.inc on line 89 If I remove constructor on derived class Articles result don't change Please help me Hi, I have the following code: Code: [Select] case "Twitter"; echo 'Twitter gadget will show here'; break; I need to make it so it's like this: Code: [Select] case "Twitter" AND $member['top'] == "1" echo "Twitter Gadget will show here"; break; I need to add a IF onto the CASE is it possible? Thank you. hey guys im having a few problems with my query if anyone can please help...the two problems im having is
1.the total price returning as 00106. price = 100.00 and p_and_p = 6.00 in the database...im after a figure that looks like 106.00
2. @category will be a parameter like :category which will be binded to a value like 'al'l, 'videos', 'dvd's', but if the parameter is ALL i dont want to join my categories table allowing it to select all rows regardless of the category
any help, pointer would be truly appreciated...thank you
SELECT @category := 'Videos', i.item_id, i.title, i.price, i.p_and_p, SUM(i.price + i.p_and_p) AS `total_price`, i.listing, i.condition, CONVERT_TZ(DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY), '+00:00', u.time_zone) AS `end_date_time` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id CASE @category != 'All' THEN LEFT JOIN categories c ON c.name = 'Videos' END CASE JOIN users u WHERE u.user_id = '7' AND MATCH (i.title, i.description) AGAINST ('bla' IN BOOLEAN MODE) AND i.start_date_time < NOW() AND DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY) >= NOW() GROUP BY i.i I have an existing instance of my class Database, now I want to call that instance in my Session class, how would I go about doing this? Hi Can you call Class A's methods or properties from Class B's methods? Thanks. If a class has a constructor but also has a static method, if I call the static method does the constructor run so that I can use an output from the constructor in my static method? --Kenoli Ok. I know you can pass the object of a class as an argument. Example: class A { function test() { echo "This is TEST from class A"; } } class B { function __construct( $obj ) { $this->a = $obj; } function test() { $this->a->test(); } } Then you could do: $a = new A(); $b = new B($a); Ok so that's one way i know of. I also thought that you could make a method static, and do this: (assuming class A's test is 'static') class B { function test() { A::test(); } } But that is not working. I'd like to know all possible ways of accomplishing this. Any hints are appreciated. thanks I need to make the following code work without case sensitivity. For example, if this was processed, I would like for $message to be changed from "Stupid is not a nice word. Ugly is not nice either." to "unintelligent is not a nice word. unattractive is not nice either." For my purposes, I don't care that the capitalization changes, I just need the $goodwords to be replaced with the $badwords regardless of capitalization. Any ideas here? Code: [Select] <?php $message = "Stupid is not a nice word. Ugly is not nice either."; $badwords = array("stupid", "ugly"); $goodwords = array("unintelligent", "unattractive" ); $message = str_replace($badwords, $goodwords, $message); ?> How do I make the username and password checking CASE SENSITIVE? $result=sprintf("SELECT * FROM db WHERE username = '%s' AND watchword ='%s'", mysql_real_escape_string($username), mysql_real_escape_string($password)); Thanks. Bickey. |