PHP convert array values to lower case

Hi Guys, Just a quick tip that I think could be useful for newbees. There are times when we want to do some silly things with our arrays like converting all the values to uppercase or to lowercase or make first character uppercase. This post will show you how you can use PHP's inbuilt function to convert all array values to lowercase and then we'll make first character uppercase for all the values and then finally we will change everything to uppercase Ok so consider this array To Convert all values to lower case in above array we use function array_map as shown below Above will print As you see we are using array_map function above. Definition of array_map is below where callback is user created function or a php function that we can utilize. we used strtolower above, next we will use function ucfirst and strtoupper on resultant arrays from array_map function Now lets convert the resultant array values to be first character uppercase Above will result in Now using the same technique with change the first param value i.e. callback function to strtoupper to convert array values to uppercase as shown below   Above will result in So you see how we used our inbuilt php functions to get the required result. I hope this helps Cheers Advertisement       … [Read more...]

WordPress JC Coupon Plugin Free

Hi Guys, I created this plugin to make my life easier for myself. I am pretty sure that this will help you too. Let me go through some key features that you are going to get in Lite version of this plugin. Ok So let's check what features this plugin has Got? Add Coupons to your Posts and Pages Destination URLs are masked Over 4 styles and many combinations to create a right coupon for yourself. It can carry Title, Description, Savings message and Expiry date Live preview while you create your coupon You can add coupons that never expires with custom Expiry text option. The only way someone can get a coupon is with a Click. However you can choose to show your coupon and Click is not necessary then. Coupon gets copied to clipboard when your visitor clicks on wrapper layer and are then taken to the affiliate website. When coupon expires it will just disappear from your Posts or Pages Very handy Coupon management User can Vote whether Plugin worked for them or not so that you can take an appropriate action. Many other features are available in PRO version. At the end of this Article I will explain what you can do with PRO version Now that I've listed the key features of Lite version. Its time to check out some screenshots Plugin Management As you can see there are many key features shown above. With management you can Delete, Modify and Reset User votes. Duplication of a Coupon is available in Pro Version Now lets check how does Add a Coupon looks   Ok in the above screen there are heaps of options. Notifications works with Pro version only. Other than that you can use everything. The screen gives you lot of flexibility to create a C code that suits you. Once you create a Coupon a shortcode will be generated which you can copy and paste in your Posts or Pages and it just works flawlessly. Below is a screen shot that shows a coupon consumption   Above screenshot looks a bit dated … [Read more...]

PHP Curl download contents of Web Page

Hi Guys, Would like to share this quick tip. CURL is a very unique and well know library used by PHP community to make HTTP and other sort of web request. My friend asked me if Curl can download a page contents from Web. My answer was Yes it can. PHP supports libcurl, libcurl is a library created by Daniel Stenberg (a genius from my point of view), that allows you to connect and communicate to many different types of servers. Below is the list of protocols it supports http https ftp gopher telnet dict file ldap Today we will be using a quick HTTP call to http://jaspreetchahal.org and try to download my home page. Lets find out how we can achieve this Know more about PHP curl options from here http://www.php.net/manual/en/function.curl-setopt.php Above function can be used as below There are many other options that would be handy to add in your curl request depending on what you are trying to achieve. A request can be as simple as get page content and as complex as logging in, setting cookie and then download content.   I hope this post helps you.   Cheers, Advertisement       … [Read more...]

Jquery check if checkbox is checked

Hi Guys, Just a quick tip here. This gets me every time so I thought I should better write about it so that I remember it next time I use it :) There are couple of ways to check if a checkbox is checked or not. A quick on is Read more about is() function here http://api.jquery.com/is/ Another method is to check the checked attribute Lets see how that is done Now the main difference between above two method is that is() either returns true or false whereas attr()  in this case will return string e.g. "checked" when checkbox is checked Read more about attr() here http://api.jquery.com/attr/ I always use is() for these types of checks because it is more natural and is read very well e.g. psedo code "if checkbox is checked" But it all depends on you what fits better. Performance wise I don't think there will be much difference though.   I hope this helps Cheers Advertisement … [Read more...]

WordPress Using Media uploader in your plugin

Hi Guys, I have to agree that with wordpress, possibilities are infinite (may be). As I am still learning Wordpress API and still have to master the art of Hooks and Crooks (I mean filters) :), I had developed very basic plugins for my couple of website but they were really basic. So everyday with Wordpress I am learning something new. Last week I learned how can I use the available Media Uploader that ships with Wordpress. So rather to reinvent the wheel, you can use whatever is already available Ok so lets get started. First You will need couple of includes so in you admin_init action or whichever hook you are using to enqueue the scripts put this code there This makes sure that thickbox (modaled window) and media-upload scripts are available. As you notice that we've imported thinkbox style too. Wordpress knows where these scripts are so you don't have to worry about the paths here. Ok So this is done Now we will create a very basic form as shown below. This form will be on one of your Admin pages. Advertisement   Now that our HTML Form has been setup lets do some jQuery magic to open media uploader page. you can place this script just under your form or you can include it in your JS file. because we are using document.ready (pseudo) so the script wont execute until the page get loaded completely. Ok so this way we will have our file or image uploaded and have path of the Image which we can store in database or do other manipulations.   I hope this Tip will help you. I will be writing on how to add custom buttons on top of content editor soon so stay tuned Till then Adios!   Advertisement … [Read more...]

WordPress SMTP settings

Hi Guys, I am developing a plugin for wordpress and it is soon to be launched. While developing this plugin I wanted to test email functionality that is built in. WordPress uses PHP's mail function to send email So to send message to external email address your local machine should be able accept your message for relay in other words localhost is by default seen as a mail server. In other words Wordpress doesn't have any its own settings to configure a SMTP server. It assumes PHP's mail function is working properly to send emails. With Linux I guess either sendmail or postfix are used my many distros and are good enough to accept and send email to localhost user email address. For *IX machine check where your php.ini file is and provide path to sendmail in following setting ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ;sendmail_path = But if you are running Windows box for you plugin development, then changing main PHP.INI file is what you are looking for. So look for these settings [mail function] ; For Win32 only. SMTP = localhost smtp_port = 25 ; For Win32 only. ;sendmail_from = me@example.com and make changes accordingly. bottom line is that the SMTP server you will be using should accept anonymous emails and it should accept emails from your development host IP too. I can cover more advanced setup for mail servers but that's not this post is about. Now you can also set wordpress to work with gmail etc. i.e. external Mail Servers In wordpress 3.3.x Open /wp-includes/pluggable.php and you will find function called wp_mail That's the function that is used to send emails right! On line number 210 you will see this declaration Just below that you will find that it gets initialized if its missing. Now on line 394 you will find this declaration Change above to this   You have 2 options here. Either to append these lines and after the above line and … [Read more...]

WordPress How to get wp-includes path

Hi Guys, First thing first, I am developing my 3rd wordpress plugin and this one is for public consumption. While developing this plugin I have this problem where I wanted to include PHPMailer class from wp-includes folder. But the way I wanted to do was to make it generic so that plugin won't break with directory changes. This is what I can up with. This solution can be improved and other one will exist too but its worth checking this tip So here are my solutions Pre-requisite to the method below is that wp-content and wp-includes are under same parent folder, which I hope is that case for majority of wordpress installs So as you see that what I've done is that I used WP_CONTENT_DIR constant available in wordpress code as of version 3.3.2 Another method is Pre-requisite is that immediate parent to wp-includes is wordpress install folder. ABSPATH returns path to wordpress root. You can also use $_SERVER['DOCUMENT_ROOT'] but I find above method more reliable in all means. You will need to atleast include your wp-config.php file in order to make above work. There is more expensive way too to iterate through the directories to find your file, but I doubt that that's a good Idea. I guess if you are reading this and have something more to add for other visitors please use comments to add your feedback to this topic.   I hope this helps Cheers,         … [Read more...]

jQuery string split explode method

Hi Guys, So my colleague asked me how do we split a string into multiple parts like the way we do with explode method in PHP. I doubt that there was something that exists with jQuery but I was sure that I used split() method available in Javascript. So with jQuery why reinvent the wheel when you can use something that is provided to you by native browser supported Javascript. Lets see how we can split the string below and store splitted chunks in array In Javascript we do something like this Advertisement   Now if I try to look into my javascript debug console, I'll see my string perfectly splitted into an array as shown below I can access individual element as shown below To take it one step further lets iterate on the above return array with jQuery and traditional javascript :)   I hope this post will help you in some way Cheers, Advertisement     … [Read more...]

jquery htmlEntities Encode and decode HTML characters

Hi Guys, Just a quick tip here. So with my current project I have this requirement to Encode and decode HTML chars using javascript. Well luckily I am using jQuery which makes it kinda easy So if you have a string shown below Now if you do this in jQuery Advertisement   You will get this as output And for an opposite effect you can do this You will get this as output   I hope this tip helps you   Cheers Advertisement   … [Read more...]

Servicestack Markdown NoRender Master Layout Page, Render partial content

Hi Guys, I am dealing with the Client End for a project that I am working on and the Client is written purely in HTML5 and Javascript with some CSS3 magic. Now we are using ServiceStack and Markdown templating engine as our Web service and Content providers. So you know that when calling a specific service the output can be any of the following JSON HTML XML CSV JSV   The above are really handy when you want to load your javascript Grid, or display content as HTML. Now if we think about the bigger picture we have couple of things when the output is returned as HTML. First consider this from Markdown Docs Once the appropriate view is executed it's output is stored in the **'Body'** variable and is merged with its static website template. The rules for finding the appropriate master website template is simple: It's the first **default.shtml** page it can find, looking first in its current working directory then recursively up the directory hierarchy until it finds one. The view is merged with the static website template by replacing all **<--@VarName-->** with variables generated by the page (i.e. in ScopeArgs). i.e. the executed output of the View is stored in the **Body** variable and is embedded in the static website template by replacing all **<--@Body-->** found. Advertisement   That's good that the View is processed and merged to the Master website template what what about if we don't want that default action to happen? Ok so this is what you can you. Its called Bare HTML return So for instance if you are accessing a page like localhost/yourwebservice/param (which kicks the default merge with Master them)  then you can change the URL to this localhost/yourwebservice/param?format=html.bare This will override the Fusion of MD template to the Master template. Now there are some scenarios where you will want to select a custom Master … [Read more...]