Posts Tagged ‘PHP’

Importing large databases on Wamp5 PHPmyAdmin, how?

Tuesday, August 24th, 2010

Have a database bigger than 2MB? want to import them somewhere else? but you cant and PHPmyAdmin just gave you the dead end message below?

No data was received to import. Either no file name was submitted, or the file size exceeded the maximum size permitted by your PHP configuration. See FAQ 1.16.

Have no fear, there’s a solution:

Look for the php.ini file -> c:/wamp/www/apache2/bin/php.ini

Then change the following lines:

post_max_size = 8M
upload_max_filesize = 2M
max_execution_time = 30
max_input_time = 60
memory_limit = 8M

To these new values:

post_max_size = 100M
upload_max_filesize = 100M
max_execution_time = 5000
max_input_time = 5000
memory_limit = 100M

Then restart wamp5 and retry importing…

Happy coding :P

How will I know if im on Joomla! home page or in innner page?

Tuesday, May 25th, 2010

As the title suggest, how will I know if I’m on Joomla! home page?

for example:

if('ImOnHomePage'){
  do this...
}else{
  do this instead...
}

A quick answer should be via PHP $_SERVER global variable:

<?php
$uri = $_SERVER['REQUEST_URI'];
if ($uri == "/" || $uri == '/home.html') {
  echo 'Im on home page';
}else{
  echo 'Im not on home page';
}
?>

Please before trying to update or change your templates/TemplateName/index.php file please do make a backup. It can save your life :)

Adding space before every capital letter in a string via PHP preg_replace() and regex

Monday, April 26th, 2010

Hello again everyone, I found this great regex which is very effective in adding a space before every capital letter.  You can think a lot of things where to use this function.

So without further blah blah,  see the function below :)

<?php
 
function SpaceBeforeCapital($string){
	return preg_replace('/(?<!\ )[A-Z]/', ' $0', $string);
}
 
$SampleString = 'ReginValerianoWebDeveloper';
 
echo SpaceBeforeCapital($SampleString);
 
?>

Result string below:

Regin Valeriano Web Developer

NOTE: Im not the original writer of the regex I just found it on the web, I think its interesting, gave it a try and it works :) now made as a function.

The easiest way to get file’s extension name via PHP

Wednesday, March 17th, 2010

Hello, again I found a new way, easiest way(as far as I know) for us to find, get and use file extension name via PHP (PHP 5.2.0 or greater).

thru a function called “pathinfo()”. :) yup a pre defined PHP function to get file extension, and they put it there for us to abuse haha.

ok lets begin.

<?php
$file=pathinfo('http://www.yourwebsite.com/uploads/image.jpg');
 
echo $file['extension'];
 
?>

This of course will print “jpg”. Which is the file extension of our file image. Easy huh…

More on pathinfo()

<?php
$file=pathinfo('http://www.yourwebsite.com/uploads/image.jpg');
 
echo $file['dirname'], "<br />";
echo $file['basename'], "<br />";
echo $file['extension'], "<br />";
echo $file['filename'], "<br />";  
?>

this will print out the details below

http://www.yourwebsite.com/uploads
image.jpg
jpg
image

Thats it for pathinfo()! :) see u round…

Validating email via regular expression

Tuesday, February 23rd, 2010

You have an online form.

You want to validate every field,  especially email input fields.

You do not want just check if its has a value of not, but also if its in the right format (e.g. email@email.com).

If you answered yes to all of these then the function below if perfect for you.

Check it out…

function validate_email($email){
     if(!eregi("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$", $email)){
	  return $error=1;
     }
}

Fell free to abuse…