PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 10 votes, 4.50 average. Display Modes
 
Unread Dev Shed Forums Sponsor:
  #61  
Old April 4th, 2006, 10:34 AM
mateoc15's Avatar
mateoc15 mateoc15 is offline
C A R D S
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: The 'Ville
Posts: 890 mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 22 h 58 m 41 sec
Reputation Power: 14
Quote:
Originally Posted by chads2k2
#45 - Why can't I use my javascript variables in PHP?

Also, just think about it. In the code sample given by chads2k2 when the PHP page is loaded it is parsed into HTML. At that point your prompt hasn't even been displayed and the user hasn't even had the chance to set your NAME variable, much less let the PHP engine parse it and place it in the place where you're calling $_GET['NAME']. JavaScript is executed after the page is loaded.
Comments on this post
chadsmith729 agrees: Brilliant!
__________________
SELECT COUNT(*) FROM fun WHERE location = 'WORK' AND day_of_week IN ('MON','TUE','WED','THU','FRI');

COUNT
-------
0

Reply With Quote
  #62  
Old May 2nd, 2006, 08:05 AM
chadsmith729's Avatar
chadsmith729 chadsmith729 is offline
--Retired--
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Sep 2003
Location: Enjoying forum retirement.
Posts: 3,122 chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 19 h 29 m 21 sec
Reputation Power: 1021
#47 - How do I get PHP to work based upon the location of their IP address.

There are a couple of things that you need to know before you start doing this. The first being that the IP address could be a spoof, or could be based on a proxy server. This means that you will not always be assured to get the IP address of the actual user. The second thing that you must know is that even if you get the IP address it might be from AOL, MSN, Earthlink, ect which setup a block of addresses that always look like they are coming from the United States.

So, if you are going to use this information to determine what language to have your website display you might want to consider these. However, if you evaluated the risks and you see nothing wrong with doing what you are doing then here are some links that can help you out with the code and such:
http://www.maxmind.com/app/geoip_country
They even have a PHP api:
http://www.maxmind.com/app/php
__________________
Get A Supplier LLC | Hilarious Comic

--- Pretty much retired from the forum. I will get back on every now and then, and maybe answer a few questions.

Last edited by chads2k2 : May 2nd, 2006 at 08:06 AM. Reason: Coloring the top

Reply With Quote
  #63  
Old May 2nd, 2006, 08:55 AM
mateoc15's Avatar
mateoc15 mateoc15 is offline
C A R D S
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: The 'Ville
Posts: 890 mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 22 h 58 m 41 sec
Reputation Power: 14
Regarding the above post: It's not a good idea to use IP address as a unique identifier of your user because (among many other reasons) dial-up services in particular give dynamic IP addresses. Basically, every time the user connects they get a new IP address.

Reply With Quote
  #64  
Old May 11th, 2006, 10:05 AM
chadsmith729's Avatar
chadsmith729 chadsmith729 is offline
--Retired--
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Sep 2003
Location: Enjoying forum retirement.
Posts: 3,122 chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 19 h 29 m 21 sec
Reputation Power: 1021
#48 - Resizing an image with PHP
Many have asked this in the past and a couple of people have responded in a way that doesn't actually answer the question. The question being, how do I resize an image with PHP? Yes this will work for larger images going to smaller, but smaller images to larger the math doesn't work out really well.
PHP Code:
<?php
//imageScale (image Location, new image width, new image height)
//You can choose the new Width, or new Height but not both (if you're going by Height, put a -1 for new Width
//will return an array, element 0 is the new width, element 1 is the new height
function imageScale($image$newWidth$newHeight)
{
   if(!
$size = @getimagesize($image)) die("Unable to get info on image $image");

   
$ratio = ($size[0] / $size[1]);

   
//scale by height
   
if($newWidth == -1)
   {
      
$ret[1] = $newHeight;
      
$ret[0] = round(($newHeight $ratio));
   }else if(
$newHeight == -1){
      
$ret[0] = $newWidth;
      
$ret[1] = round(($newWidth $ratio));
   }else{
      die(
"Scale Error");
   }
   return 
$ret;
}
?>

PHP Code:
////  USES
$resize_array imageScale("images/image_name.jpg",357,-1);
echo 
"<img src='images/$image_name' width='" $resize_array[0] . "' height='" $resize_array[1] . "' alt='Image' />"


Hope that clears it up,
Chad

Last edited by chads2k2 : May 11th, 2006 at 11:21 AM. Reason: Kicken brought up a good point.

Reply With Quote
  #65  
Old May 11th, 2006, 11:18 AM
kicken's Avatar
kicken kicken is offline
Wiser? Not exactly.
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: May 2001
Location: Ft Myers, FL
Posts: 4,556 kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)kicken User rank is General 4th Grade (Above 100000 Reputation Level)  Folding Points: 182227 Folding Title: Super Ultimate Folder - Level 1Folding Points: 182227 Folding Title: Super Ultimate Folder - Level 1Folding Points: 182227 Folding Title: Super Ultimate Folder - Level 1Folding Points: 182227 Folding Title: Super Ultimate Folder - Level 1Folding Points: 182227 Folding Title: Super Ultimate Folder - Level 1Folding Points: 182227 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 Weeks 6 Days 20 h 48 m 16 sec
Reputation Power: 1243
Send a message via ICQ to kicken Send a message via AIM to kicken Send a message via MSN to kicken
Quote:
Originally Posted by chads2k2
#48 - Resizing an image with PHP


Actually, with that code you don't need the GD library at all.

Quote:
Originally Posted by php manual
Note: The getimagesize() function does not require the GD image library.


Also note, that unless the scaling you're doing is minor (as in only around a 50-100 pixel change) then you'd probably be better off using gd to actually resize the image, for two reasons:

1) The quality will almost certainly be better. Browsers generally do a fast resize resulting in a poor but quick resize operation.
2) You save bandwidth because the file size actually is reduced. By having the browser resize the image, the entire file must still be downloaded rather than just a small thumbnail like version.
__________________
Spidermonkey Tutorial; Fight me: http://aoeex.mybrute.com
http://www.aoeex.com/gmap.php - Put yourself on the map (Now Updated!)


Reply With Quote
  #66  
Old May 11th, 2006, 01:04 PM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 30 m 28 sec
Reputation Power: 1046
This should give you most of the detail: http://www.tutorialized.com/tutoria...-with-PHP/11878

Reply With Quote
  #67  
Old July 9th, 2006, 09:19 PM
chadsmith729's Avatar
chadsmith729 chadsmith729 is offline
--Retired--
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Sep 2003
Location: Enjoying forum retirement.
Posts: 3,122 chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 19 h 29 m 21 sec
Reputation Power: 1021
#50 - Windows Apache MySQL PHP (NOT XAMPP,WAMP,appserv)


Recently there has been far more discussion about security and setting up a server the proper way than I care to think about again. Every answer seems to be some prebuilt solution that everyone swears is the end all to server setup. I disagree completely with using a premade system such as appserv, XAMPP, WAMP, or anyother system that is developed for the sole purpose of double clicking and having the entire system setup correctly the first time. That is not how you setup a server. Nor will it ever be that way. I mean MySQL, PHP, and Apache are free. You would think that one of them would already have thought about incorporating it all into one package, ask yourself why they haven't done so? It comes down to security for one company may not be secure enough for another, one size does not fit all.

Some have said that it is hard. That by doing this it will be difficult getting it setup. I agree that in the beginning it is a bit difficult, I mean with all the reading you will have to do. The reading that is required is reading the installation text files and maybe a config file or two. Where even those configuration files are so well commented it's amazing. Take the time to read php.ini file line by line. You will walk away with a greater sense of how the system works, moreso that just having something else configure it for you.

I can assure you one thing. If you setup your own server you will gain experience, and knowledge, but more importantly you will gain the self rewarding notion that you took the time to do it right the first time. You didn't cut to the easy way when you had a choice.

Every pre-made system was put together in what they think is a "perfect" system. Will it work for your own server? Sure, but will it be the most secured perfect system for your application? No. Ask any hosting company if they use XAMPP, or WAMP, appserv and they will (or should) laugh at you. It is fine (I guess) for localhost checking to ensure that your scripts work. But what will you say if your boss (present, or future) asks you to setup the server for your companies website? Will you tell them that you double clicked a setup.exe file and you're ready to go? Hopefully not.

Where to get the stuff:
PHP (GET THE ZIP FILE!!!)
Apache2
MySQL 4 or 5

Instructions (other than the install.txt file in PHP's zip)
Very good tutorial! Well written that has easy instructions.
http://www.webmasterstop.com/48.html
http://www.apachemysqlphp.com/

Doing it right the first time will make all the difference in the world,
Chad
Comments on this post
bluedragon agrees: Totally agree : Xampp and the like are great for localhost when starting out . . . but learn how to
do it on your own!
trinisam agrees: Excellent advice...

Last edited by chads2k2 : July 19th, 2006 at 09:06 AM. Reason: Added another tutorial.

Reply With Quote
  #68  
Old October 4th, 2006, 10:36 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
User, Contributing
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Oct 2006
Location: Texas, USA
Posts: 3,832 ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 10 h 13 m 20 sec
Reputation Power: 1695
Quote:
Originally Posted by ape2man
#30 How do i str_replace thats not case sensitive

PHP Code:
/* Was submitted by jpenn : Senior Member */

function stri_replace$find$replace$string )
    {
    
$parts explodestrtolower($find), strtolower($string) );

    
$pos 0;

    foreach( 
$parts as $key=>$part )
        {
        
$parts$key ] = substr($string$posstrlen($part));
        
$pos += strlen($part) + strlen($find);
        }

    return( 
join$replace$parts ) );
}

echo 
stri_replace$find$replace$string ); 



Easier, I think, to do a preg_replace with the i modifier:
PHP Code:
 $new_string preg_replace("/$find/i"$replace$original_string); 


Faster than jpenn's implementation I think. Although that's pretty good as well.

-Dan

Reply With Quote
  #69  
Old December 29th, 2006, 09:13 AM
srisa srisa is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2006
Location: I'm sneaking up behind you.
Posts: 1,201 srisa User rank is Captain (20000 - 30000 Reputation Level)srisa User rank is Captain (20000 - 30000 Reputation Level)srisa User rank is Captain (20000 - 30000 Reputation Level)srisa User rank is Captain (20000 - 30000 Reputation Level)srisa User rank is Captain (20000 - 30000 Reputation Level)srisa User rank is Captain (20000 - 30000 Reputation Level)srisa User rank is Captain (20000 - 30000 Reputation Level)srisa User rank is Captain (20000 - 30000 Reputation Level)srisa User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 23 h 10 m
Reputation Power: 250
You can use the inbuilt function str_ireplace(search, replace, source)

Reply With Quote
  #70  
Old May 7th, 2007, 02:52 AM
helloakash's Avatar
helloakash helloakash is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: India
Posts: 851 helloakash User rank is Colonel (50000 - 60000 Reputation Level)helloakash User rank is Colonel (50000 - 60000 Reputation Level)helloakash User rank is Colonel (50000 - 60000 Reputation Level)helloakash User rank is Colonel (50000 - 60000 Reputation Level)helloakash User rank is Colonel (50000 - 60000 Reputation Level)helloakash User rank is Colonel (50000 - 60000 Reputation Level)helloakash User rank is Colonel (50000 - 60000 Reputation Level)helloakash User rank is Colonel (50000 - 60000 Reputation Level)helloakash User rank is Colonel (50000 - 60000 Reputation Level)helloakash User rank is Colonel (50000 - 60000 Reputation Level)helloakash User rank is Colonel (50000 - 60000 Reputation Level)helloakash User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 15001 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 2 Days 5 h 47 m 15 sec
Reputation Power: 543
Send a message via Google Talk to helloakash Send a message via Skype to helloakash
Orkut
Quote:
Originally Posted by scoutt
but to answer you, you can't chmod files in windows. you don't need to.


#51 - Can I change the file permisions/attributes in Windows
There is attrib command in windows to change the file attributes.
Syntax:
Code:
ATTRIB [+r|-r] [+a|-a] [+s|-s] [path\file] /s
__________________
Akash Dwivedi
"Whatever the mind can conceive and believe, the mind can achieve."
Feel good..



Last edited by helloakash : May 7th, 2007 at 02:54 AM.

Reply With Quote
  #71  
Old September 6th, 2007, 04:18 PM
chadsmith729's Avatar
chadsmith729 chadsmith729 is offline
--Retired--
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Sep 2003
Location: Enjoying forum retirement.
Posts: 3,122 chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)chadsmith729 User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1Folding Points: 298927 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 19 h 29 m 21 sec
Reputation Power: 1021
#52 - How do I suppress errors in PHP?

I have been seeing this problem come up a lot and figured I would put this in the FAQ of PHP.

--- The @ symbol:
You can place an @ symbol in front of the function and it will not have the error be displayed. You can view more about this here.

--- error_reporting()
You can use the function error_reporting() to suppress all errors with:
PHP Code:
 error_reporting(0); 

--- Fool proof way
There is one fool proof way of making sure that no errors will show up, that is to test your application throughly. When you test your application as thoroughly as you possibly can you will see most errors (syntax, fatal, ect) and then you can fix your application. You can suppress the errors but you aren't fixing anything, fix the application then if errors exist move to plan B. Remember that errors are coming up for a reason, find out what the error is and fix it. Use one of the above ONLY when your application is ready to go live and you are sure no errors should arise anyway.

Hope this helps,
Chad

Reply With Quote
  #72  
Old September 6th, 2007, 05:19 PM
sryuuza's Avatar
sryuuza sryuuza is offline
today is tomorrows yesterday!
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Nomadic
Posts: 1,058 sryuuza User rank is Sergeant (500 - 2000 Reputation Level)sryuuza User rank is Sergeant (500 - 2000 Reputation Level)sryuuza User rank is Sergeant (500 - 2000 Reputation Level)sryuuza User rank is Sergeant (500 - 2000 Reputation Level)sryuuza User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 4 h 53 m 56 sec
Reputation Power: 15
Send a message via ICQ to sryuuza Send a message via AIM to sryuuza Send a message via MSN to sryuuza Send a message via Yahoo to sryuuza
Info Post Only: How to Convert Decimal to Time

This post is not a question, but rather an answer to a question I have seen asked but unanswered around the internet.

How do I convert a decimal to time?

PHP Code:
function makeTime($num){
    
//make string into int
    //add hours to return value
    
$timeLeft intval($num).":";
    
//subtract string from int, multiply by 60
    
$num -= intval($num); $num *= 60;
    
//add leading zero if needed
    
if(strlen(intval($num))==1){
        
$timeLeft .= "0";
    }
    
//add minutes to return value
    
$timeLeft .= intval($num).":";
    
//subtract string from int, multiply by 60
    
$num -= intval($num); $num *= 60;
    
//add leading zero if needed
    
if(strlen(intval($num))==1){
        
$timeLeft .= "0";
    }
    
//add seconds to return value
    
$timeLeft .= intval($num);
    
//return final string.
    
return $timeLeft;
}

echo 
makeTime(1.5); //prints "1:30:00"
echo makeTime(23.7111111); //prints "23:42:39" 


Enjoy!
__________________
If This Post Was Useful, Please Click The Next To My Post
SantaMail

Saidan Ryuuza

Web Designer | Writer
Web Confidence Design
Defunct Games
Kyou wa Ash!ta no Kinou


--
Failure is not an option! It comes bundled with Windows.

Reply With Quote
  #73  
Old September 6th, 2007, 05:31 PM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 30 m 28 sec
Reputation Power: 1046
Following on from the above, if you're going to use the @ operator, you should manually test return values.

Eg. some older libraries are happy to chuck a warning if something isn't perfect (like really old versions of the older 'mysql' library which would chuck a warning if you tried to use mysql_fetch_<whatever> on a result object that returned no rows. In fact the easiest way to do this is something like the following:

php Code:
Original - php Code
  1. if ($row = @ mysql_fetch_assoc($result))
  2. {
  3.   //do something
  4. }


This provides safety and also handles the problem of 'what if i reached the last row?'.

I tend to do something similar to the above (wrapped around my homemade database class) in a while loop:

php Code:
Original - php Code
  1. while ($row = $db->next)
  2. {
  3.   echo "Hello, {$row->name}!";
  4. }


The reason the above work is because a non-empty array counts as true in a boolean context, so when you get passed false (the only other possibility than a non-empty array), the loop terminates. My database class returns a resultset class which functions like mysql_fetch_object but has more functionality, and the same applies here, my class returns false if there are no more rows.

Reply With Quote
  #74  
Old September 6th, 2007, 05:31 PM
codergeek42 codergeek42 is offline
Insert clever user title here.
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jul 2003
Location: Anaheim, CA (USA)
Posts: 6,550 codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 16th Grade (Above 100000 Reputation Level)  Folding Points: 39542 Folding Title: Starter FolderFolding Points: 39542 Folding Title: Starter Folder
Time spent in forums: 1 Month 2 Weeks 2 Days 5 h 42 m 41 sec
Reputation Power: 2075
Send a message via ICQ to codergeek42 Send a message via AIM to codergeek42 Send a message via Yahoo to codergeek42 Send a message via Google Talk to codergeek42
Facebook
Don't forget about strftime and mktime.
__________________
~~ Peter ~~ :: ( Who am I? ) :: ( My Blog: A day (or more) in the life of a CS & Math student... ) :: ( Supporter of the EFF & FSF ) :: ( I'm a GNU/Linux addict and Free Software Advocate. ) :: ( How to Ask Questions the Smart Way ) :: ( The Fedora Project, sponsored by Red Hat ) :: ( GNOME: The Free Software Desktop Project ) :: ( GnuPG Public Key ) :: ( About me on the WIki )

Reply With Quote
  #75  
Old September 6th, 2007, 05:50 PM
sryuuza's Avatar
sryuuza sryuuza is offline
today is tomorrows yesterday!
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Nomadic
Posts: 1,058 sryuuza User rank is Sergeant (500 - 2000 Reputation Level)sryuuza User rank is Sergeant (500 - 2000 Reputation Level)sryuuza User rank is Sergeant (500 - 2000 Reputation Level)sryuuza User rank is Sergeant (500 - 2000 Reputation Level)sryuuza User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 4 h 53 m 56 sec
Reputation Power: 15
Send a message via ICQ to sryuuza Send a message via AIM to sryuuza Send a message via MSN to sryuuza Send a message via Yahoo to sryuuza
I apologize if this is posted in the wrong area, I did not realize there was a specific section for answers...

as for mktime and strftime they don't exactly work in the same way. To my knowledge neither are about to handle decimal to time conversion out of the box. mktime requires you to specify hour, min, sec and so on individually.

If you know of a shortcut to performing this outside of a function, or a way to optimize the function using either one of these, please let me know.

Thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > [NEW USERS] - Answers to Frequently Asked Questions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek