Home > Tags > PHP
Page 1

PHP to Static HTML On The Fly

Data driven web sites are da bomb, in my not-so-humble opinion. The ability to drive information through a slim passage and have that information display, in various ways, is without a doubt amazing. Anything can be manipulated, altered, structured, added, removed and decided before it even hits the screen. Systems like WordPress, Joomla, Drupal have had their day in the sun. On the horizon are even more progressive, minimalistic UCGm [User Generated Content management] systems that will have all of us programmers gushing like school-boys. Old[er] folks, like myself, who worship L, M, W -AMP need to sharpen our skills, keeping marathon pace with the wondrous changes in the digital universe.

Recently, I was faced with a serious issue for a clients website, where -due to their server set up- and limited ability to get noticed by the Big3 Searches. If fact, with the Panda/Penguin frequency and alterations for “YingBook” {yahoo, bing, facebook} social search, the site all about keeled over. The problem was: her pages were getting ignored or the database would go offline for exceeding the 128 limit. Evn after increasing to 256 the site was still @ a snails pace. Not to the point of tears, she asked me why she could not just create Static pages like the old days {html4}, using the current CMS platform.

My explanation was nothing short of a technical plethora, of which she was oblivious. Finally, I said to her, “We can set up a system to transfer all your data based pages into static html, that you can edit on-the-fly. Long story short, as a marketing “gurette” of sorts, is now working with me to develop a strategy to offer the general population such a program -primarily for mobile/wireless devices like iPad, Android maybe even SUR.

The PHP to static HTML works quickly and effectively, to take the information and create  fully functional, SEO friendly pages, without the trapped header or slugs limitation often associated with CMS programming. It can even include breadcrumbs or anything, really, that fits into a traditional web page. I first used this approach for rebuilding RSS Feeds ala minute as pages were changed/updated, created or deleted from the system. A very efficient, lightweight measure, that truly boosted visibility, while providing an outlet from the data doldrums and easy enough for the novice designer or non-tech to use.

PHP > HTML

Collect Data from Database Get Static or Template Elements Parse PHP to HTML Reload Sitemap/RSS

Database Checkpoint – Update or Create?

Simple and easy. Get the post Title, etc. Do the error checking, like empty, too short or too long. Apply the errors for all the additional items like photo, video or audio formats (extensions), content word count, etc. Once complete, we execute two options. Does this Title exist? If yes, update the record by this author, back-up the old page into a zip file, unlink the old page, create a new page and reload the RSS feed. Else, add the new record to the database, create a new page and reload the feed.

/* Check for Errors */ $TITLE=$_POST['TITLE']; if($TITLE=="") {die('Title cannot be empty');} else { $skunk=array('+','-','_','!','?','...','*','&','%','=','~'); $TITLE=str_replace($skunk,' ',$TITLE); $TITLE=str_replace(' ',' ',$TITLE); } if(strlen($TITLE)<12){ die('Please make the Pubtitle more than 12 letters');} elseif(strlen($)>40){ die('Please make the Pubtitle less than 40 letters');} else { $TITLE=strtolower($TITLE); $TITLE=ucwords($TITLE); } /* Check Title Database */ $title_chk=mysql_query("SELECT * FROM `PUBS` WHERE TITLE='$TITLE'") while($row=mysql_fetch_array($title_chk)){$TITLEX=$row['TITLE']; if($XTITLE==$TITLE){ UPDATE TABLE WITH NEW INFO /*Zip old File*/ $zip = new ZipArchive(); if($zip->open('$TITLE-$date.zip', ZIPARCHIVE::CREATE)...
more →
Michaelmd says: its a pity cms framworks don't do this ... 50 or more mysql queries just to show a page in many of them is just ridiculous. as...

PHP Web Page Security Generator Script Tutorial

This tutorial outlines the Captcha objective, how-to design and code your own security script, using PHP. Although considered by the masses to be a very complicated maneuver, protecting web pages, as well as internal elements of those pages, is actually quite simple. So, why are these Captcha and ReCaptcha solutions so complicated and difficult to use? The only honest response I can give you is: marketing.

No matter what anyone tells you, at the end of the digital day, these beautifully designed, engaging, stimulating and appealing folds of information are just that: pages. If these pages were printed pages, then Captcha would be a child-proof seal on each one. And for those forward thinkers out there, you guessed it: Captcha is actually a type of password. And passwords are a hackers biggest challenge. Captcha, ReCaptcha and now Image Captcha are like child-proof seals that even adults cannot open – without wanting to smash that plastic container to pieces – with seething teeth, watery eyes and narrowed brow, rip out the cotton and snatch that little purple pill, with a madman’s sort of satisfaction.

What Is CAPTCHA Actually?

First, let me break down the basics, for those who are novice programmers or frightened web site owners. Captcha is specifically a non-trademark of Carnegie Melon University, where a group of programmers elite scripted a method for reducing, or eliminating, unwanted injections to any web page. This was called Completely Automated Public Turing [to tell] Computers [and] Humans Apart. CAPTCHA. That is quite an interesting thing. How does an automated machine tell the difference between an automatic keyboard stroke and a human induced keyboard stroke? And here the fun begins. The keyboard. That poor, coffee-stained, crumb and eyelash laden attachment, that permits we humans to transform our thoughts into digital fandango! What the algorithm did was create an automated password system or security portal, to capture potential hacks, and stop them in their tracks. Think: a RAID© commercial for data driven web-pages. As of late, we have seen Captcha go steroids. But, no matter the bloated and vigorous attempt at security, that solution comes back to one thing: the password.

How The Solution Works?

So, how does the Captcha thing actually work? When a person enters or presses a key on the keyboard, a specific language command is executed and prints the keystroke into the input box. This box is designed to store the keys or characters entered until the return key is pressed and the information put through several tests behind the page. These tests are specifically designed to determine if the keys entered match the security code of the script, whether or not these keys contain unreadable characters, or if there are excessive characters -like programming code or hyperlinks- within. There are a few more tests the system performs, which I shall not indulge/bother you with. Point being, these keys or characters are a set of variables passed through pages, using scripts called security checkpoints. In short, a password checker.

Sure, you can ask me –err, ASCII Anything

How does the algorithm/script determine what key is correct or incorrect? Ah, yes. Now that is the real question and what this article is destined to do: relieve some of that child-proof frustration. Your keyboards, actually all keyboards, essentially operate under the same system. This system of key-press or key-strokes is called ASCII.  ASCII (pronounced: a-ski) is an acronym for American Standard Code [for] Information Interchange. The core language is based on American English, used for most devices that print text. In fact, the origin of this code is telegraph. Yup, like Morse code. Then evolved from typewriters to these massive key-punch systems, and finally reduced to keyboard size, as personal computers became increasingly popular. ASCII has also been revised for non-English speaking keyboards, but the code per stroke remains the same. In essence, each button on your keyboard has a digital command behind it, be it in Russian, Cantonese or Arabic. Some of these commands are non-print or non-character based, others are print or character based. Some, as you might have guessed, can be combined to form other commands or changes in characters. A good example is simply pressing the F1 key, which is a command to open the help desk of your machines operating system or pressing the CAPSLOCK, transforming the letter “a” into “A”.

The ASCII code comes in a variety of methods used, like ASCII Art, which uses characters to form Images or extended codes like Unicode, which have more characters in their system. The standard ASCII contains 128 units. Of those 128 units, 95 are considered printable characters. The remaining 33 are non-print characters, like BACKSPACE, RETURN, NULL, etc. So, it is in the ASCII 95 that the use of Captcha is -or was- used. It is precisely within these 95 characters that all passwords are generated. In essence, you could create a password that is 95 char long with a probable 9,025 password variations, using the ASCII 95. Wow, that is a lot of combos! Indeed. But, machines are “smart”, meaning the people who designed ASCII, Captcha, passwords and web pages are the same kind of people who invented robots -and are the same kind of people known as hackers or phreaks. So, why all the fuss, if ASCII can produce 9,025 variations of characters? Wouldn’t this alone hinder security breaches in web pages? It can, and does. But, invention is one of those things. Especially for programmers, perfecting the invention is often more fun than the original. What more fun could there be than competing against other like-minded individuals making the process challenging on higher levels? Captcha took on a new level by introducing a very strange kind of password system. What do I mean? Well, look at any web page. What is the first thing you notice about it, besides the striking images? Still guessing? Hmm. Give you a hint. Your reading it right now. Ding! The text.

That Is Some Kind Of Fontastic News!

That text, printed ASCII, is based on a character output known as Fonts. Depending on your System [PC,Mac, Mobile] you will notice there many different kinds of Fonts. Some fonts work only on certain machines, while other fonts are universal. Still more fonts can be installed on machines and, of course, on web pages. This is what makes them so rich and fun to engage. Scribbled-loop-de-loop or collegiate-block-bold, they make the web a lot more interesting. However, the ASCII commands are the same, no matter what font is used. Programmers know this. They also know that they could mathematically program a script to create those 9,025 variations of printable Key-Strokes. So, to change-it-up, keep the robots confused -and make half the adult computer-user population go blind with frustration- Captcha decided to create a Font system of their own. Fonts that look shaded, ultra-thin or resemble a really obscure Rorschach test. By combining various Font types, the system prints these obscure Letters or Numbers to keep machines from reading them, automatically. Or do they? Honestly, I have yet to see how. In fact, I know many web sites that are still getting spam and injections with the use of Captcha. Why? Because the key-strokes are still the same. But, now they have gone the route of Layered Fonts. Remember, fonts are actually Images -called Glyphs- stored in a specific file type. These font types are commonly referred to as TrueType or OpenType. But, there are many, many Font types from strict Mac to Adobe PDF. What is being done now is layering multiple font types, with distorted background images, even background glyphs, to further hinder the automatic hacker. Still, though, the letter & number key-strokes are still the same.

There are a great number of characters that can be applied to create passwords, because the ASCII system has 128 characters (255 extended). One of the strange things I noticed with Captcha and other programs, was the use of only letters & numbers in the system. Which sounds reasonable, since most passwords are specifically letter-number combos. In fact, the typical password system utilizes only a portion of the keyboard-stroke command, about 59 characters, providing 3,481 probabilities for any letter-number combo. Out of 9,025, that’s just one-third of the available units. Yeats & Keating!

The first group of characters, ASCII 1-31 are specifically non-character or non-print commands. So, they do nothing for creating passwords. Most password systems use letters and numbers also known as alpha-numeric characters. Many assume these characters are stored somewhere, either in a database or flat-file. But, since I know that a security checkpoint does not need to be saved to the database or flat-file, realized there was a lot more potential in creating a security portal, than a blurred ASCII Art rabbit {although it was really cute}. Adding the “unused characters”, created my own version of Captcha. I combined the units 32-47 + 58-64 + 91-96 + 123-126. Yes, I could have even applied the ASCII Extended units, up to 255. But because they are called HTML special characters, like copyright symbol or accented Latin, and do not appear on the keyboard itself, left them alone. Not that they cannot be used, they CAN! But it would make more work on the actual human and make me a Captcha monster -literally and figuratively. So, this added an additional 29 units to the available list of ASCII characters for a grand total of 88 characters out of 128, within the range of 32 and 128, respectively. The new probabilities or combos then are 7,744.

Scripting Web Page Security Measures

For the most part, a n00b programmer can design and implement their own web security system, using several approaches. And since the newer versions of Captcha are causing the not-so-visually impaired to become visually impaired, staring at those glyphs, have decided to think out of the box.

What are some of the ways to use the ASCII system to create security portals? Well, one way is to use the additional characters mentioned. This expands the password range from 3,481 to 7,744 -almost double. Sweet! Achieving this basically requires selecting the number of characters for output. They can be from one to eighty-eight characters in length. But 88 char is a bit excessive, not to mention most machines tend to stop reading an input-field after twenty characters, simply because it begins to eat up automated time-lines. Spammers do not want to get noticed. They want the fastest in-out possible, so they can move on to the next victim. I found that even groups work best, like 6 or 8 characters in length. A six-eight combo yields 36-64 probabilities per instance or display.

One approach I used, which has been extremely effective, is to simply apply a static background color to the password display area. This is achieved by creating a SPAN next to the input-field and doing a little CSS majik. The output was quite clean, simple and readable by the average human. Because I wrapped the output in a span, it is unlikely a robot or automatic spammer would “look” for it. They usually look for “input type” names or pre~fill fields. The ouput script produced a combo of lowercase and uppercase letters, as well as, numbers and symbols. This alone reduced spam on one of my clients websites to zero. I kid you not. Another way using this same method was called forced highlight. The page background was white and security output color white. Just above the input-field, I made a notation for the visitor to highlight the area and read the code.

Brilliant! This made it even easier for the real human, because they could just copy-paste the security code in, and oblivious to the robot or spammer -who could not even see the text.

.comment span {background: rgb(50,100,150); color: rgb(255,255,255); padding:10px; font-size:14px;

The PHP Generator Script

With the aforementioned comes the need for the code, which you will use to create the output characters. It is very straight-up easy to do using PHP. What this means, in layman’s terms is: the code is executed or run either before the web page loads, when a button is clicked or the Enter Key pressed on your blessed keyboard. This is extremely beneficial to creating “hidden” commands and functions in 1.43 seconds of load-time. The code works like this:

Create a command-line function to generate a random string of characters. The initial result is NULL, because there are no characters, yet. To create the character set -or string length- we use the FOR command. Calculate a RANDOM string of the ASCII characters between units 32 and 126. Again, you could include the glyphs and accented characters up to 255. The result now is relative to the selected number of random characters. We return the string result and give the generated characters a specific name (SNAP1). The key to making the entire script effective is in the last 3 bits of script. Executing the number of characters to display at load-time. In this case, it is six (6). Place a hidden field with this code echoed in it, to compare to the inputted text, by the visitor when the form is submitted. No bloating, no waiting, automatically generates the script (have yet to see the same output twice).

function generateRandomString($length) { $result=''; for($i=0; $i<$length;$i++) { $num=rand(32, 126); $result.= chr($num);} return $result;} $SNAP1=generateRandomString(6);

Applying User/Member IPA as a Web Page Security Code

Up until now, we have focused on just one parent method of creating security measures for web pages using the ASCII or Key-Stroke approach. Which, by all accounts, is very effective for applying child-proof seals. The only draw back to this method is, of course, the character base itself. At some point, a machine or spammer can catch on to Captcha. Probably further demonstrates why they are coming up with new -and maddening- methods to blind the seeing. Nevertheless, another powerful approach is to use the visitor’s IPA, Internet Protocol Address. Every time someone visits a web page, their IPA is available for capturing.

In fact, companies like Alexa, Bing, Quantcast and Yahoo use the IPA to deliver visitor details to web owners. It is also where spammers tend to hide and attempt to drop iFrame ads or harvest browser information. This is formally known as malware or spyware. So, a very nifty approach I used was to take the visitors IPA, manipulate the information to make it “unfriendly”, save that IPA, along with browser details, to a database table. Yes, this is a much more complex method to securing web pages, but is extremely useful to sites wanting stronger measures than just a simple Captcha code.

The following scripts are very fast and effective ways of using the visitors IPA to increase page security. The IP Address is stripped of its “.” leaving just the numbers. You could then manipulate the string by inserting a SPACE between each letter and using the same Captcha generator, insert special characters between. In short, instead of the user inputting a password, the system generates the security code based on their IPA. You could even trick-things up a bit by reversing the IPA, then adding a space and special characters, plus further truncated characters from the ASCII “Captcha” Generator.

Strip  ‘.’  {original : 241.931.74.240  | new: 24193174240 }

str_replace('.','',$IPA);

Reverse IPA {original : 24193174240 | new: 04247139142 }

$IPA=strrev($IPA);

Add Whitespace {original : 04247139142 | new: 0 4 2 4 7 1 3 9 1 4 2 }

$IPA=wordwrap($IPA,1," ",true);

Test out methods, ideas and approaches using this concept and tell us how they worked. Hey, you never know. You could be the inventor of the Next Generation of Web Security. Happy Coding!

...
more →
Kasey Bonifacio says: I've never heard that PHP stands for Pre Hypertext Protocol. PHP originally stood for Personal Home Page but was later changed to...

Python and Web: Building Dynamic Web Forms in Web2Py from Ground – Part III

Welcome to the third and final tutorial in the series of creating dynamic web forms using Web2Py.

In the second tutorial of this series, we talked about editing/updating/deleting the submitted form records as well as management of those records using an ingenious function named SQLFORM.grid(), which allowed us to import and manage our form records in a pre-built environment having security features enabled.

In this third, and final tutorial of the series, I would like to shed some light on how multiple web forms can exist on a single page, how a single form can submit data to multiple tables, and finally, a hint about modifying CSS of your web form (which is a common practice in classical PHP based web forms). The reason why I am going to this extent is just to ensure you that web forms in Web2Py are no second to PHP forms, and they have everything that a PHP form can offer – our forms require even less amount of coding, which is exactly the reason why Web2Py and other Pythonic web frameworks are getting popular.

Okay, let’s go.

1. Multiple Forms on a Single Page:

As the header suggests, we are going to integrate more than one web forms on a single page, arranged serially against each other. All these forms will be linked to different tables in the database, but will be incorporated and controlled using a single controller (in our case it is form_a()) function.

We already have one form in place, so we will define two more tables for two additional forms in our default.py:

db.define_table('registration', Field('firstname', requires=IS_NOT_EMPTY()), Field('lastname', requires=IS_NOT_EMPTY()), Field('gender', requires=IS_IN_SET(['Male', 'Female'])), Field('username', requires=IS_NOT_EMPTY()), Field('password', 'password'), Field('image', 'upload')) db.define_table('personal', Field('nick_name', requires=IS_NOT_EMPTY()), Field('address', requires=IS_NOT_EMPTY()), Field('married', 'boolean'), Field('zip_code', requires=IS_NOT_EMPTY()))

Now we have two database tables named ‘registration’ and ‘personal’ having following fields:

registration:

Firstname: Lastname: Gender (Drop-down): Username: Password: Image (Upload Field):

personal:

Nickname: Address: Married (Check Box): Zip Code:

Once the database tables are defined, let’s work on our controller function to incorporate the two forms based on them:

def form_a(): form1 = SQLFORM(db.registration, deletable=True, upload=URL(r=request, f='download')) if form1.accepts(request.vars, session): redirect(URL(r=request, f='form_a')) qq = db().select(db.registration.ALL) form2 = SQLFORM(db.personal, deletable=True, upload=URL(r=request,...
more →
Stan says: you gave an interesting idea which feels refreshing to an old time php developer. lol. very informative article by the way.

Create Custom Username RSS Feed Using PHP

So, you built a website with an amazing strength of potential for millions of internet aficionados to venture, read information, blog, whatever –and maybe make you a few pesos in the big scheme of things. There is a simple, yet powerful tool to gain traffic through: RSS.

RSS means Really Simple Syndication. To syndicate just means gather all the information in once place, where people can subscribe via their web browser, to an article list. But, the words “really simple” on the programming side, are not so simple –as you might have guessed. Creating an RSS Feed, should be quite easy. And after racking my brain for days over the programming connection between my existing PHP website and testing out several Feed Generators { like Mag Pie or Simply Smarty } had a moment where my iMac nearly plunged out the window.

Luckily, I remained calm and went back to my old school PHP programming know-how for the answer to Customizing An RSS Feed without bloated parsers. The customization of this type of Feed creates a Username based RSS Channel in PHP, that returns valid. For each user generated page, you can place the link to that specific group of Articles on the website. The system automatically creates the files needed with each registration. This means less work for you, more flexibility, certainly no manual entry – and if all goes well, increased subscribers.

Creating the entire Custom RSS Feed will take you minutes, literally. From here you can allow Members to jack into Feedburner, Pheedo or any other Syndication they prefer, which can also be used for Internal Tax and Folks -onomy. You will need three {3} items in all:

A Make File function at Member Registration The PHP-XML Hybrid File { template } The Output Script/Feed Link

1. A Make File function at Member Registration

On the Registration Confirmation page call a MAKE FILE function. This tells the server to create a file titled Username.rss.php.  It is vital you make this file, else the RSS Output will not be created. The function gets the POST Username and tells the server to MAKE FILE called Username.rss.php.

$USERNAME=$_POST['USERNAME']; $FILE=$USERNAME.'.rss.php'; if(!$handle=fopen($FILE, 'a')) { echo "Crickets, cannot open file ($FILE)"; exit } $ginger=file_get_contents("rss.php");

2. The PHP-XML Hybrid File { template }

Now, here is the tricky part: you will need to GET the base RSS-PHP hybrid Template. Why? This saves a lot of time and headache. The function gets all the Template information and appends it to the new file called Username.rss.php. This will include the RSS Elements for each Member who joins. Write the header to the new RSS file and move it to the proper directory. { You may choose whatever folder you like, just so long as you remember where you created it so you may link it later on }. The above code now automatically creates the RSS-PHP file in that directory. In order for that file to be created, you need the base code or Hybrid Template, and obviously a connection to the database.

3. The Output Script/Feed Link

One of the unique features of RSS, it is written in XML. Essentially, you can customize the items like Title, Main URL, Main Photo and Child Elements as well. Some browsers will enable photos for each feed listing, some do not. Feedburner and Pheedo definitely do, by creating an XHTML (XML+HTM) page for the feed. This is great for putting in Ads.

The issue with RSS/XML and PHP is simply the language. Communication between is like speaking Russian to a Dolphin, neither understand a word the other is saying. However, there is a way to unite the languages and everyone go home happy. This is called parsing. One language meets another and information is translated. In fact, the parser IS the translator. To make this work, we tell the server this PHP File, should be read as an XML file. This is found in the Content Type. Most web pages tell you in the header what type of content is designed or allowed for the page. If you are using XHTML Transitional or even Strict, you can display pretty much any code. With PHP/XML you need to specifically assign which Content Type. In this case, XML/RSS. Let’s create the Main RSS Template file first and customize it.

header(Content-Type: application/rss+xml; charset=ISO-8859-1); require_once('mydataconnect.php'); $USERNAME= basename($_SERVER['SCRIPT_FILENAME']); $USERNAME= str_replace('_',' ',$USERNAME); $USERNAME= str_replace('.rss.php','',$USERNAME); $USERNAME= strtolower($USERNAME); $USERNAME= ucfirst($USERNAME); $feed = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $feed .= '<rss version="2.0">'; $feed .= '<channel>'; $feed .= '<title>Your RSS</title>'; $feed .= '<link>http://www.yourwebsite.com</link>'; $feed .= '<description>Describe...
more →

Getting Started with Python Programming: Creating a Blog

How do you create a simple, dynamic website using the Python programming language? In this tutorial we are going to learn how to do exactly that. First, lets get some basics about Python.

Classes and Methods in Python

Python is primarily object-oriented. Class instances (objects) in Python are defined as shown below:

class coder: coding_languages = 10 david = coder() david.coding_languages = 5 print “David knows s languages.” % david.coding_languages

Running the above script from the terminal gives the results below:

“David knows 5 languages.”

Methods in Python are functions contained within a class. Methods are written in Classes and referenced using objects. Methods are defined as shown below:

class coder: coding_languages = 10 def learn(self): print “I know s languages.” % self.coding_languages

Consider another method below:

class google(coder): def chrome(self): print “Ow snap!” david = coder() david.chrome()

Variables get inherited the same way as Classes.

In languages like PHP, you only need to code the functions specific to your website. When using Python you can use frameworks like Django, Web.py, Grok and TurboGears. When using Django, install it both locally and on your server when deploying. Django is an MVC framework which is feature-rich and its tutorials are easily available online and this is what we are going to be using in this tutorial.

Creating a Simple Blog

Start your first Django project using the command below:

Django-admin.py startproject SimpleBlog

When you list the files inside the above folder, SimpleBlog, you will see three files have been created: manage.py, settings.py and urls.py

We will start by creating our first app as follows:

Python manage.py startapp blog

This creates a directory called “blog” which is our app. We need to define our models using the models.py file. For a blog we will need a table. We create a table as shown below:

class posts(models.Model): author = models.CharField(max_length = 30) title = models.CharField(max_length =100) bodytext = models.TextField() timestamp = models.DateTimeField()

After installing mySQL as your database, install the Python library for interfacing with the DB (I use Easy Install) and then create the database. Set your Django project to work with your mySQL database.

Add all the models we created into the database using the command below:

manage.py syncdb

This command simply adds new fields and does not alter existing ones in the database.

Set up the urls pattern (urls.py) to the appropriate module as shown:

Urlpatterns = patterns(), url(r’^$’, ‘SimpleBlog.blog.views.home’, name= ‘home’),

Under views.py, add the code below:

from django.shortcuts import render_to_response from blog.models import posts def home(request);...
more →
Karl says: your templating system for the code has completely destroyed the right python syntax. You might have to fix a few things such as...

Code Snippet to Find the Number of a Certain Value in an Array (PHP)

I recently developed an application that sent variables into a mathematic function. This function needed to have a numeric count of the exactly how many zeros there were in a certain array. For this snippet, we can use both numeric and text based arrays.

I printed it using this code:

Our two example arrays will be:

$array_num = array(1, 1, 1, 2, 3, 4, 4, 4, 4, 4, 5, 6); $array_text = array(apple, apple, apple, orange, banana, banana);

We then put this array into array_count_values()

$count_array_num = array_count_values($array_num); $count_array_text = array_count_values($array_text);

If we print $count_array_num we get this result:

Array ( [1] => 3 [2] => 1 [3] => 1 [4] => 5 [5] => 1 [6] => 1 )

if we print $count_array_text we get:

Array ( [apple] => 3 [orange] => 1 [banana] => 2 )

From these results, we see the exact number of each value in the respective array.

Then we can define the values that we want to know:

$value_num = '4'; $value_text = "banana";

Finally, we can use this code to get the count for how many times the number 4 shows up in our $array_num and how many times ‘banana’ is listed in $array_text.

$result_num = $count_array_num[$value_num]; $result_text = $count_array_text[$value_text];

And of course, echo the results!

echo $result_num; echo '<br/>'; echo $result_text;

Now our page result will be:

5

2

And there we have it, now you can plug those variables in any where you’d like! Feel free to ask any questions below!

...
more →
Deval Panchal says: Thanks you for sharing with us this kind of information......... Sigma Solve I truly like to reading your...

7 Tools for Responsive Web Design

The move towards developing responsive websites has introduced a set of new tools that help can developers learn the ropes fast and start producing cross-browser and non-device specific websites quickly and more efficiently. Let us see some of these tools and resources that you can leverage as we get deeper into responsive web design:

Adaptive Images

Your website is increasingly being viewed on smaller screens that consume low bandwidth. In addition to other challenges associated with developing for small screens, image resizing is one of the things to take into consideration. Fortunately, Adapative Images, a PHP script that works on any website, can help in this regard. Adaptive Images detects screen sizes abd re-scales versions of your HTML images, ultimately helping you deliver small images to small screens.

FitText

Have you ever desired to have scalable headlines that fill the width of parent elements when developing fluid layouts? The JQuery plugin will allow you to resize your fonts and ensure that they fit where they are supposed to regardless of the device or browser.

PhotoSwipe

Did you know that you can deliver fancy image galleries common on desktops to mobile devices? This free HTML/CSS/JavaScript library enables developers and designers looking to add the look and feel of native apps on their websites the ability to provide visitors with an intuitive interface to interact with images on your mobile website. It is compatible with all popular Javascript libraries and frameworks.

Less Framework

When building websites with multiple layouts, it is important to maintain consistency. By having a layout based on the same grid, it is possible to reuse elements by simply adjusting widths, font sizes or other small detail. This is the whole idea behind Less Framework. Having a common baseline grid allows everyone the freedom to keep writing code their own way while ensuring consistency.

Check out our series on Learning Less from Alex Ball.

Skeleton

By use of CSS files, it is possible to design responsive sites rapidly. Skeleton makes this possible by use of a lightweight 960-grid as its base that allows elegant scaling down from laptop browser windows to mobile window screens in both landscape and portrait format. It comes with lightly styled forms, tabs, buttons and other elements that form the basic foundation of any mobile website.

Responsive Testing Tool

Now that you have your responsive site under development, how do you test during development? It turns out that browser security will not allow you to navigate through frames. Matt Kersley, a designer and developer, has designed a testing tool to help you with that. The tool can be downloaded from Github and installed on your website hosting to allow testing during development.

Inuit CSS Framework

With HTML5 support, inuit.css comes with a custom grid builder for developing fluid grids. The framework is progressive and flexible; it sets sensible boundaries to what you can do while giving you total controltfo what you can do.

Please feel free to share some of your favorite tools for developing responsive web sites as well.

...
more →
Daisy Bono says: A proper web design can make or break a company’s online business model. Hence an appropriate site that caters to a company's...