You can do a lot of different things for your website in PHP, Lets go over a very cool technique that has many applications, be it separating features, tags, etc…
String delimiting
This is a very cool technique that you can use for a wide variety of things, the one we will be talking about is how to use it for displaying different features for a product on an e-commerce website.
Let’s say you have a nice simple e-commerce website, you Login, you go to add a product, let’s say the fields are:
Title/Description/Features and Price
On your website you want all your features to display as a list, yet you don’t want to have to code it up and set a limit to how many features you can have, so what can you do?
Break up your string! When adding features separate them using some character that is likely never to be used in describing your feature… i.e (; (a semicolon)).
So the content in your features textarea will look like this:
cool; shiny; well worth the cash; attracts the ladies;
How do we get this to display as a list item on our product detail page? easy follow the steps below.
1- Set up a new string variable to store the features – On your code that displays the product features you will have to do the following; In this example we will assume this is coming out of a database.
$your_string = $row['your_product_features_field'];
2- Use the explode function – this function breaks your string up and inserts each value as a value in an array.
$your_string_array = explode(';', $your_string);
3- Create a loop – Loop through your array and put each value of the array into li’s
foreach($your_string_array as $product_feature){
$feature_list .= "<li>".$product_feature."</li>";
}
4- use your new feature list variable.
That was easy wasn’t it?
This is the full snippet of the code:
$your_string = $row['your_product_features_field'];
$your_string_array = explode(';', $your_string);
foreach($your_string_array as $product_feature){
$feature_list .= "<li>".$product_feature."</li>";
}
If you have any questions just ask and i will be happy to help. Long live web design london!

