Showing posts with label Tip. Show all posts
Showing posts with label Tip. Show all posts

Javascript Clean HTML

>> Tuesday, April 24, 2012

Normally when using WYSIWYG editors liks CKEditor, you allow the user to enter poorly formatted HTML, this isn't really a big issue most of the time, but you have to be very careful with this, for example, if you allow them to enter any html, they could easily send a tag with a custom request, and XSS injection.

This isn't about security but a little help with managing the generated HTML, I needed a function to clean empty tags, thanks to the awesomeness of Regular Expressions, I ended up with this little guy


String.prototype.htmlTrim = function () {
        return this.replace(/<(p|div|span|b|u|i|strong|em|h\d+)>\s*\n*\t*[ ]*\s*\n*\t*<\/\1>/, '');
};

That will clean all empty tags, but it won't fix much more. Anyways! I think this might be helpful for some people so I'm sharing it here.

Usage is


myString.htmlTrim();

Read more...

How To Install PostgreSQL And phpPgAdmin Support In XAMPP

>> Friday, February 25, 2011

I'm working on akaikiwi and I want to test some stuff on Postgre, as the databases I'm aiming to support are SQLite, MySQL and Postgre, the latter is the only one XAMPP doesn't support natively.

I found a great post on How To Install PostgreSQL And phpPgAdmin Support In XAMPP that worked nicely, except in the last part, I had to add

Alias /phppgadmin "D:/xampplite/phpPgAdmin/"

 AllowOverride AuthConfig
 Order allow,deny
 Allow from all

Inside alias_module instead of mime_module, but other than that, it works like a charm :)

Read more...

Sending mails from localhost with XAMPP Lite

>> Monday, February 21, 2011

One of the most common tasks of web development is sending emails, whether from a registration process, password recovery or if they suscribed to an update, you will need to send emails. The problem is that XAMPP doesn't have a default configuration for sending mails, and developing without this ability is pretty dull, you need to test your mails!
But don't worry, you won't have to install anything, and you wont need a hosting, you just need a Gmail or Hotmail account.

  1. Edit your php.ini file located inside the php folder of your XAMPP installation path.
  2. Search for the line ';sendmail_path = "\"YOUR_XAMPP_PATH\sendmail\sendmail.exe\" -t"'
  3. If it has a ';' in the beggining, remove it
  4. Edit sendmail.ini file inside the sendmail folder
  5. Add the following lines
  6. account Gmail
    tls on
    tls_certcheck off
    host smtp.gmail.com
    from [your-email]@gmail.com
    auth on
    user [your-email]@gmail.com
    password [your-password]
  7. Finally edit the account default line, it should look like this
    account default : Gmail
  8. That's it! Now restart apache and you can now send mails.
If you want to use Hotmail instead of Gmail just change the host to 'smtp.live.com', the email adresses, and if you want, the account name (Hotmail instead of Gmail).

Read more...

Creating Anonymous PHP Objects

>> Saturday, February 19, 2011

So I'm working on akaikiwi and found out a very nice thing, which doesn't really help me right now, but I really feel like sharing it, as I'm sure it'll be useful for somebody.

$obj = (object) array('foo' => 'bar', 'property' => 'value');
echo $obj->foo; // prints 'bar'
echo $obj->property; // prints 'value'

That's it! That will cast the associative array to stdObject. Useful to save some code.
In PHP 5.3 you could actually also use closures to make some nasty stuff, it's a pity PHP 5.3 is still not widely used.

Source: http://www.php.net/manual/en/language.oop5.php#84292

Read more...

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP