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...]

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...]

WordPress How to increase max file size upload limit

Hi Guys, Just a quick tip guys Sometimes you want to upload a file that is larger than your current upload limit how then you can change that limit Well first of all this is not a wordpress problem that is something to do with your settings that you have set in your php.ini file. Two of the important settings are called upload_max_filesize post_max_size Other values that you may consider reviewing are You might want review those ini entries: (If changing above setting does not help then increase these values and try again) session.gc_maxlifetime max_input_time max_execution_time Now if you have access to your php.ini file then search for these properties. In my case I wanted to increase my limit from 8MB to 15MB so this is what I did     This helped me resolve my problem. Hope this will help you too.   If you are on shared hosting make sure you can override these settings in .htaccess files. In .htaccess override these settings: php_value upload_max_filesize    15M php_value post_max_size          15M php_value session.gc_maxlifetime 36000 php_value max_input_time         36000 php_value max_execution_time     36000   Consider reading this article if you want to enable .htaccess if it is not enabled http://www.php.net/manual/en/configuration.changes.php Please share if you got any questions   Cheers. … [Read more...]

Yii framework case insensitive URLs

This is really a quick tip, So sometimes we may want to treat our urls in case sensitive way, this applies to when you are hosting on Linux, and sometimes you want them to be treated the same regardless of the case   So what you need to do is to open your main.config file and look for urlManager component. by default this component is commented as shown below   Now just after urlFormat item add another array item as shown below Important bit above is introduction to caseSensitive setting above and setting its value to false. By default its true   I hope this helps Cheers … [Read more...]

Yii framework hide index.php

Hi Guys, So after a long time I had to setup another Yii based site. Yes and I found myself in same old unfamiliar Yii setup territory :) Even though it all good when you end up setting it up but there are few things that I need to remember and hiding index.php is something that was on top of the agenda. So set this up create a .htaccess file in directory where your index.php file is and enter the following Above means that if file or directory do not exists then redirect all requests to index.php As you notice that we are using RewriteEngine directive thus it becomes important that you have this line uncommented #LoadModule rewrite_module modules/mod_rewrite.so in you httpd.conf file. Before you restart your apache server make sure that your project directory settings has AllowOveride All directive set as shown below   Restart your apache server. Well if you still don't see anything happening then goto your config file under webroot/protectect/config/main.config and uncomment urlManager component it should look like this   I hope this helps. I am pretty sure that I will come back to my post again in few weeks time :) Cheers. … [Read more...]

ExtJS 4 php get request payload

Hi Guys, I am pretty sure that you will know this one but in case you don't then this post might help you. This post is not about how to create a ExtJS grid. Please follow Extjs 4's documentation for that. This post is about data handling at server side. While using data writers such as JSON common when you use Ext JS Grid, when you try to update, create a row or cell the data is posted to your PHP script as RAW POST. Ok may be I am not making any sense at this stage so consider a Grid such as  shown below     And when I try to change Unit price above as shown below It will create a request such as shown below   Now the Request payload data is not directly available to you as such in $_POST. Instead its a raw post which you can read at server side as shown below If I use print_r() on my $rawpostdata I get this In the above code this is main part $rawpostdata = file_get_contents("php://input");   You can also set always_populate_raw_post_data =truein your php.ini file so that the raw post is available to you in global var $HTTP_RAW_POST_DATA. When using file_get_contents("php://input"); you will need to take care because it does not support enctype="multipart/form-data" I hope this helps Cheers … [Read more...]

NuSphere phpEd code completion can’t find my classes

Hi Guys, I had this problem with phpEd when I upgraded from version 6 to version 7. After I reloaded my projects Some of the classes went missing from the code completion 35% Off .Coms As a first step in troubleshooting this I thought maybe this has something to do with restarting the machine after my upgrade. I did that but the problem was still there. So I thought what could be wrong. I had similar situation before too and I fixed it before and couldn't remember how I did it then. Scratched my head and yes I remembered and was able to solve this problem Here are the steps you will need to follow.   Right Click on Code Explorer window and Click Refresh from the Context Menu. Step 1 should initiate a re-scan of you project files and the code completion cache will be re-built. If that doesn't work then start afresh. See Step 4. Check where your project's .PPX file is. e.g. If your project name is fooproj.ppj then your .PPX file name should be fooproj.ppx. Close your IDE. Delete .ppx file Re-open the project.     Now because the IDE will re-scan your project files again thus your completion cache will be rebuilt. I hope this helps Cheers! … [Read more...]

play .flv file

Hi Guys, So I did some research on this. Research means Googling :) and I thought why my Media Player wont play FLV files. Obvious answer is that FLV format is not support by media player. Where to next. I was glad to find out that a Free player called VLC player can play that for me Here is the features page for VLC player. http://www.videolan.org/vlc/features.html You can download it here http://www.videolan.org/vlc/ Now the reason. FLV is a proprietary media format for video content delivery over the internet. Video stream included in the FLV file can be a variant of H.263 standard or the other advanced VP6 codec. As an example youtube uses H.263 which is referred to as FLV1 and FLV4. Thus you can upload and view both types of formats to/from YouTube. Now because FLV needs a codec to run thus it by default wont play on any player which does not support FLV file format. Thus VLC becomes a really good choice because of all the file format support it have out of the box. So download it.   However you can also fix your windows media player too by installing codec files. You can look up for FFDShow Video decoder which can be found here http://www.free-codecs.com/download/ffdshow.htm If you want to go directly to the download page then this is the link http://www.free-codecs.com/ffdshow_download.htm At the end I was able to play my FLV file :) I hope this helps Cheers.     … [Read more...]

php sitemap.gz gzipping your data in php

Hi Guys, This is really basic stuff and I will not go into much complexity and will only give you something that is required to gzip your sitemap.xml data or any other file data and store it to a new file   Say your file name is sitemap.xml and is located in your server root use the code below to compress your data   More information on gzip functions can be found here under zlib http://au.php.net/manual/en/ref.zlib.php   I hope this helps   Cheers … [Read more...]

php script function to Ping, Update Google, Bing, Yahoo, Ask.com about Sitemap change

Hi Guys, So with my current project I had this requirement to acknowledge Google, Yahoo, Bing and Ask.com about new additions to my Sitemap.xml There are a few ways you can approach this problem. There could be other Search engines that you may be interested in so search their documentation for this topic. All search engines comes with a dedicated URL where you can send a ping to with your sitemap location. You can make plain HTTP calls to the URLs shown below which in other terms sort of means pinging. But I'll give you a function that you can put somewhere in your script to automate pinging when your site adds new URLs to the sitemap. Lets find out what those urls are first of all For Google its http://www.google.com/webmasters/tools/ping?sitemap=SITEMAP_URL For Yahoo its http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=YahooDemo&url=SITEMAP_URL For Bing its http://www.bing.com/webmaster/ping.aspx?siteMap=SITEMAP_URL For Ask its http://submissions.ask.com/ping?sitemap=SITEMAP_URL Out of all the above Google is the fastest one in my experience to crawl your new additions. Ok now lets check out the PHP function and then I'll show you how to use it.   As you can see that we are using curl library to ping mentioned serach engine URLs. The function is self explanatory and there isn't much to explain. You have few URLs and one by one you are making curl requests. Lets see how to use above function     If you want to find out how to gzip your sitemap please read my next post. http://jaspreetchahal.org/php-sitemap-gz-gzipping-your-data-in-php/ I hope this helps Cheers … [Read more...]