Archive | PHP RSS feed for this section

How To Remove The Last Character in a String

How To Remove The Last Character in a String

To remove the last character (or the last X characters) of a string, just use PHP’s substr_replace() function. Basically, you just need to tell the function to replace the last character of a string (or the last X characters) with nothing. Here’s a code sample: $old_string = “One, Two, Three,”; // remove the last comma [...]

Continue reading...

How To Process Multiple SQL Statements

How To Process Multiple SQL Statements

Sometimes you’ll find yourself needing to execute multiple statements at once. The normal mysql() class only allows for single statements, but the recent mysqli() offers this functionality. To use it, follow this code example:

Continue reading...

How To Split Comma-separated Values

How To Split Comma-separated Values

To split a string that contains values separated by commas (comma-separated values), what you need is the PHP explode() function. Here’s a code example on how to use the explode() function: $cake = “slice1,slice2,slice3,slice4″; $slices = explode(“,”, $cake); echo $slices[0]; // slice1 echo $slices[1]; // slice2 And if you have a space after your comma, [...]

Continue reading...

How To Store Arrays In MySQL / PHP

How To Store Arrays In MySQL / PHP

Arrays are the best tool in the PHP language if you’re dealing with associative data. However, it’s one thing to be manipulating arrays, but what if you need to store the entire array in a database? Structuring your database table so that you don’t have to store entire arrays should be your first priority, but [...]

Continue reading...