Archive for category Web Related

How to convert an array or object into a string in php

2
Digg me

I am asked “How do I convert an array or object into a string” very frequently so I thought I would put a quick little tutorial together explaining the various different methods.

Converting an array OR object into a string(BEST METHOD)

We are going to use the functions serialize and unserialize.

These functions are very easy to use, for example converting an array or object you would do the following:


$string = serialize($objectorarray);

Now to convert the string back into an object or array we would do:


$objectorarray = unserialize($string);

It really is as simple as that, however sometimes the serialize function doesn’t do a good job at escaping characters so to get around this we do the following:


$string =base64_encode(serialize($objectorarray)); // This converts into a string

$objectorarray = unserialize( base64_decode($string)); // This converts a string into an array or object

Converting an array into a string (OLD FASHIONED METHOD).

Implode and Explode can be used to convert an array.

Look at my example below.


$myarray[] = 'Apple';

$myarray[] = 'Orange';

$string = implode('|',$myarray);

echo $string; // This would return Apple|Orange

Using the example above, the implode function takes two parameters.  First our separator and second our array.

To now convert the string BACK into an array we use explode. See the example below.


$string = 'Apple|Orange';

$myarray = explode('|',$string);

print_r($myarray);

The explode function takes pretty much the same parameters as implode except it looks for a string rather then an array.

Why would you want to convert an array or object into a string?

When saving vast amounts of data into a mysql table or even a text file, all you would need to do using the method above is save the string into the file or into a table row.  Very useful if you have plenty of dynamic data… No need to create lots of column names when you can save the object or array into a single row!

  • Share/Bookmark

, , , , , , , , ,

1 Comment

How to upload an image to the internet

1
Digg me

I have recently put together a little website that allows anybody to upload an image for free!

Please note that if the image you upload is not viewed for any longer then 3 months it will be deleted.

Click here to visit the website TheImageDump.com

Spread the word please!

  • Share/Bookmark

, , , , ,

No Comments

how to use mod_rewrite with apache the beginners guide

0
Digg me

The mod_rewrite feature can be very confusing to understand at first.

The best way to get your head around it is by looking at examples and a basic understanding of regex(regular expressions) will help.

I’m not going to post a full written tutorial about subject as there is already a brilliant tutorial out there.

Click below to view the tutorial.

URL Rewriting for Beginners – http://www.addedbytes.com/apache/url-rewriting-for-beginners/

Stupid htaccess Tricks – http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/

  • Share/Bookmark

, , , ,

No Comments

Tutorial – How to use arrays in php

1
Digg me

Using arrays in PHP can be a very powerful technique of handling data.

If you are not familiar with arrays in PHP then use simple code!

Example of simple code.

$fruit['apples'] = 'I like apples';
$fruit['oranges'] = 'I like oranges';
$fruit['banana'] = 'I like bananas';

Example of advanced code.

$fruit = array("apples" => 'I like apples', "oranges" => 'I like oranges', "banana" => 'I like bananas');

Using advanced code saves lines in the source code but if you are not familiar with arrays it could be harder to troubleshoot if you get parse errors.  Once you feel confident with arrays then I would recommend using advanced code.

Reading from arrays.

Arrays are very simple to read from.  Using our example code above, to see the value of Apples we would use

echo $fruit['apples'];

this would return: I like apples

Looping through arrays

Looping through arrays is easy too, but this is where people usually get stuck.  Just look at it from a logical point of view.  We are going to use the foreach function to go through the array.

foreach($fruit as $key => $value) {

echo $key . ' : ' . $value . '<br />';

}

This would return:
apples : I like apples
oranges: I like oranges
banana: I like bananas

Using the foreach function above, think of $key as the name and $value as the information we assigned.

If you would like any more information regarding arrays then please leave a comment or visit the PHP manual by clicking here

  • Share/Bookmark

, , , , , , , , ,

2 Comments

How to stop spam – junk mail

0
Digg me

Sick of receiving emails with the following subjects: tramadole, buy tramadol, online casino, buy soma, buy viagra, buy viagra online, cheap viagra, tramadole online etc…

Everybody suffers from spam at some point, so here’s some tips on fighting spam.

  1. Be very careful entering your email address on websites.  Some websites sell this information on to advertising company’s who then spam your inbox.
  2. Keep your personal/business email account separate. Get your self a free Hotmail account at http://www.hotmail.com and use it for filling in on-line forms.
  3. Google’s Gmail has the best Junk Mail filter I have ever seen! Creating an email address with Gmail is free and I would highly recommend this.
  4. RING THE INTERNET SERVICE PROVIDER. Ring your ISP whether it’s BT, Tiscal, Aol etc and see what they have to offer.  If they try to sell you anti-spam software then DO NOT ACCEPT.  Software based anti-spam filters work by looking at the emails once they are downloaded on your computer, we want it to be deleted BEFORE you download it!
  5. If you own a domain based email address such as matt@mybusiness.com, contact who ever hosts the email and tell them your problem.  If they have access to the machine/server hosting your emails they should be able to install anti-spam software such as Spam Assassin.  Ask them about this.

Please note this is just a small guide on how to prevent spam. If everything fails, why not just create a new email address?

  • Share/Bookmark

, , , , , , , , , ,

2 Comments

Faceparty goes on strike!

0
Digg me

Faceparty.com the social networking website, has gone on strike today against its users over people complaining about free features not being given to them -  Credits to Jack Thompson for pointing this out.

Click the image below to view what the Faceparty.com homepage said

Faceparty.com's awesome English

Maybe the competition of Social networking sites is getting too much for Faceparty.com with the rising popularity of Facebook.

  • Share/Bookmark

, , ,

2 Comments

Facebook overtakes Myspace

0
Digg me

According to comScore, Facebook pulled in 123.9 million unique visitors in May, beating MySpace’s 114.6 million.  Facebook is growing at a rapid rate!

* comScore is an internet marketing research company that provides marketing data and services to many of the internet’s largest businesses.

Take a look at the statistics below. (Click the image to view a larger copy)

  • Share/Bookmark

, , , , ,

No Comments

Firefox 3 officially released

0
Digg me

Some people are unaware that you don’t need to use Internet Explorer to browse the internet. There are even people out there who strictly use the AOL client (web browser) because it got installed when setting up their internet connection – Dam those AOL discs.

Another thing that amazes me is how some people type the website address in the Google, Yahoo or MSN live search box. The reason people get into this habit is because one of these providers has been set to the default homepage and it has always taken them to where they have wanted to go, so they stick to this method.

ANYWAY BACK TO FIREFOX

I would recommend anybody to install or upgrade to the latest version of Firefox. Firefox is more secure then Internet Explorer, Spyware and virus developers target Internet Explorer because it is the most popular browser world wide as it is installed on every Windows machine.

Reasons to use Firefox

  1. More secure.
  2. Thousands of add-ons available for every purpose, I would highly recommend AdBlock.
  3. Free!
  4. Faster at rendering pages then Internet Explorer.(People argue over this)
  5. Easy to install

Click here to download or read more about Firefox 3

There is a great article over at FlexBeta.net that gives 13 reasons why you should use Firefox.

Click here to view it – http://www.flexbeta.net/main/articles.php?action=show&id=32

  • Share/Bookmark

, , , , , , , ,

No Comments

Useful Cheat Sheets for PHP, MYSQL, HTML and more

0
Digg me

How often do you search the internet to remember that PHP function, CSS declaration, mod_rewrite expression or MYSQL query syntax?

We all do it time to time, for example the date function in PHP.  I am always having to look at the PHP.net manual for the formatting options of the date function. It is a pain!

I recently came across these GREAT cheat sheets over at ILoveJackDaniels.com -  don’t let the domain name put you off.

You can simply print them off and pin them up next to you whilst you are programming.

Take a look below:

Many thanks to ILoveJackDaniels.com for creating such useful cheat sheets.

  • Share/Bookmark

, , , , , , , , , , , , , , , , , ,

No Comments