Filed Under (codeigniter, php) by admin on 16-01-2011
The hypenated function helps you make a hypenated string.
It replaces the spaces with a hypen (-), good for SEO and clean url string.
Example: “Room nr IT Park and Country Mall”
Becomes: “Room-nr-IT-Park-and-Country Mall”
function hypenate($url){
$patterns[0]= "/,/";
$replacements[0]="";
$patterns[1]="/\s\s+/";
$replacements[1]="-";
$url = preg_replace($patterns,$replacements,$url);
return $url;
}
Usage in PHP
hypenate("The quick brown fox");
output: The-quick-brown-fox
It can also remove out specific string you don’t want to show up on your url e.g. a comma “,” just specify it on the patterns[0] array in regular expression form
$patterns[0]= "/,/";
Filed Under (codeigniter, php) by admin on 13-04-2010
Error when uploading your file using codeigniter upload
“The filetype you are attempting to upload is not allowed”
Causes:
1. Invalid file type uploaded by the user your uploading (.doc when only .xls is allowed)
2. The file uploaded is not within the specified file types added in the upload config
3. Mime type error in codeigniter caused by the mime type of the extension does not match the mime type specified in /application/config/mimes.php
Start by checking what is the mime type of the file your uploading
$data = array('upload_data' => $this->upload->data());
$mimetype= $data['upload_data']['file_type'];
echo $mimetype;
then check in the mimes.php if that mime type matches the extension you want to upload
Example:
word document
'doc' => 'application/msword'
excel file has many mime types, if its missing just add it in the array
'xls' => array('application/excel', 'application/vnd.ms-excel','application/x-msexcel')
Filed Under (codeigniter, php) by admin on 02-11-2009

In dealing with files on ci use the file helper
http://codeigniter.com/user_guide/helpers/file_helper.html
It is loaded using this line
$this->load->helper(‘file’);
read a file with read_file()
$data = read_file(‘./path/to/file.php’);
write a file with write_file();
write_file(‘./path/to/file.php’, $data, ‘w+’);
CI recommends “r+” but its better to use “w+”