Sunday, May 29, 2011

PHP remove all characters and leave only numbers

function which will remove all but leave only numbers for php:
$string = preg_replace('#[^0-9]#','',strip_tags($string));

p.s. If you are looking for function to delete all except chars and numbers look here: 

Friday, May 27, 2011

Broken image. Failed to load images fix with JQuery

Today i was solving problem with failed to load images. There was 2 solutions for this - 1) php with getimagesize and 2) JQuery check.

getimagesize showed me warnings so my choice was JQuery.

And it was great choice, because using jquery is always fun.

Code i used for all img ( CSS attribute ):

$(window).load(function() {
$('img').each(function() {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
// image was broken, replace with your new image
this.src = '';

Tuesday, May 24, 2011

MYSQL - Deleting duplicated entries huge DB

The problem occurred when i had to delete duplicated entries

like this:

id name value
502 john null
503 john null
1000 john smith

solution for this was to group by name and export them to other table

so here is mysql codes:

1. Exporting to new table
CREATE TABLE new-table-name as
SELECT * FROM old-table-name WHERE 1 GROUP BY [column by which to group];

2. Renaming old and new tables ( 'different-new-table-name' , not new-table-name )
RENAME TABLE old-table-name TO different-new-table-name;

3. And finaly renaming new table to old table's name
RENAME TABLE new-table-name TO old-table-name;

Monday, May 16, 2011

Google chrome Program too big to fit in memory [ Solution ]

Today for first time i meet the problem.

I was browsing as always... many tabs - like 10. Most of them are text. Suddenly my pc showed BSOD. After restart google chrome want start. And shows cmd windows for a second.

With cmd.exe ( start > cmd.exe ) , you can run same google chrome to see error message. It was - "Program too big to fit in memory".

After some google searches i read nothing interesting but only complains and questions about the problem.

I was not worried about my bookmarks because im using google sync.

1. So i just opened firefox.
2. Went to Google Chrome download page.
3. Downloaded / Ran setup
4. After installation all came back to normal.

Also last session was saved... and i could see pages which was opened before BSOD.

In worst situation you can lose your bookmarks. So its up to you...

Leave a comment if your bookmarks haven't erased after install. If you didn't used google sync. Cheers.

Hope it will help you guys. 

Thursday, May 5, 2011

Input is not proper UTF-8, indicate encoding !

I faced with the error while exporting huge xml.

My solution for this was changing the code:
foreach($adData as $itemData )
$xmlData .= "<item><![CDATA[".$itemData."]]></item>";

Into this:
foreach($adData as $itemData )
$table = array('&' => '&amp;', '<' => '&lt;', '>' => '&gt;', '"' => '&quot;');
$data = str_replace(array_keys($table), array_values($table), $itemData);
$date = str_replace(" ","",$data); //there is one strange square symbol. after converting into chars //for blogspot it was removed :(
$data = htmlspecialchars(html_entity_decode($data, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES, 'UTF-8');
$xmlData .= "<item><![CDATA[".$itemData."]]></item>";

Hope it will help you solving your problem.
Anyways. Good luck!