Web Design Blog - php

< Prev   1 of 6   Next > Last >>  

PHP testing if a function exists

In php you may need to check certain things are available before you call them to prevent errors or to change programming behavior depending on what functionality an object has that is passed. There are a couple functions for testing the existence of functions or variables: function_exists('func_name') isset($var) There are a couple other ones used for testing that an object/class has a method or member: method_exists($obj,'func_name') property_exists($obj,'var_name') You can also... read more!

Posted in php | Post Comment

PHP number formatting

Number formatting in php can be done in a few ways. You can simply round your number ( 2 decimal place accuracy ):   $num = round($num,2);   You can simply remove all decimals and make it an integer:   $num = intval($num);   There is even a function in php to format numbers for display:   echo number_format($num,2,'.',',');  ... read more!

Posted in php | Post Comment

PHP and ajax easy with json and jquery

Getting data back and forth between a php script and your javascript may seem like a chore. Luckily php can talk json pretty easily ( with the appropriate functions enabled of course ). Lets build a simple call that submits a number to php for calculation.   <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript">     $(document).ready(function(){         $('#calc_btn').bind... read more!

Posted in php | Post Comment | 3

php call_user_func_array and dynamic function calls

Sometimes when you are programming you want to call a specific function, but not directly as a hard coded call but instead using a string or variable for a class/function name. Here is an example. You have programmed a plugins system that has dynamic loading of your plugins. Each plugin has a static class with various functions. In your framework you want to call a specific function on all loaded plugins. You have an array with all the names of the plugins that are installed in the system. You ... read more!

Posted in php | Post Comment

php constants

Let's say you want to define a variable that cannot be changed after it is defined. You'd like to use this variable for a configuration option, message, or something else of this sort. You can do this using constants. Constants are a programming structure common in many programming languages. It is a scalar variable that cannot be changed once defined. In addition to not being changed, it is in the global scope automatically. Here is how you would define a php constant   define('MY_CO... read more!

Posted in php | Post Comment

php json_encode and json_decode

JSON is used in many places on the web. It got it's start with ajax and has trickled into use in many other places. It is being used a lot now with web API's and I have even seen it make it's way into being used as a simple way to store serialized objects. PHP has recognized the importance of JSON in today's web, with later versions of php the json_encode and json_decode functions are included in the core build. In versions earlier than 5.2 you may need to install the extension for these functi... read more!

Posted in php | Post Comment

what is base64

You may have seen a string such as "YXNkZmZkc2FhYWFhZGRkZWY=" before. Some of you will recognize this as base64. Base64 is an encoding format used to represent binary data as text. It is commonly used in MIME email formats for things such as attachments. In php, base64 funcitons are readily available for use. base64_encode($data) - encodes to base64 base64_decode($data) - decodes from base64 Typically base64 encoded data takes a third more space to store than the original, as the data is enc... read more!

Posted in php, technology | Post Comment

Save time on form programming with regex

At times we all must create some more complex and lengthy html forms to capture data from our users. The process usually entails building out the design for the form then coding the form to HTML so they are usable. After the form is programmed, it is all nice and pretty but still does not perform any actual functionality. We then need to create the programming that sits behind the form to accept the form post and do something with the data ( capture to database, perform calculations, email data ... read more!

Posted in php | Post Comment

< Prev   1 of 6   Next > Last >>  

View All Posts